
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
eslint-plugin-return-types-object-literals
Advanced tools
Ensures explicit return types on functions and lambdas that return object literals.
return-types-object-literals/require-return-types-for-object-literals
Requires return types on lambdas that return object literals.
npm install --save-dev eslint-plugin-return-types-object-literals
.eslintrc.yaml:
root: true
parser: "@typescript-eslint/parser"
parserOptions:
project: "./tsconfig.json"
plugins:
- "@typescript-eslint"
- "return-types-object-literals" # ← Add this
rules:
# ↓ And this:
"return-types-object-literals/require-return-types-for-object-literals": error
const a = () => ({
// Error: "Return type missing"
propA: true,
propB: true
});
const b = () => {
// Error: "Return type missing"
return {
propA: true,
propB: true
};
};
const a2 = (): Foo => ({
// OK
propA: true,
propB: true
});
const b2 = (): Foo => {
// OK
return {
propA: true,
propB: true
};
};
const c = () => {
// OK
const result = {
propA: true,
propB: true
};
return result;
};
Ensures excess property checking is performed on objects returned by lambdas.
type Foo = { a: boolean }
function foo(callback: () => Foo): void {
...
}
foo(() => ({
a: true,
b: false // No compile error (BAD!)
}))
foo((): Foo => ({
a: true,
b: false // Compile error (GOOD!)
}))
Without a return type, the lambda's return type will be inferred to be a supertype of the type you actually want. This means no excess property checking will occur, as the inferred return type will automatically contain every property you specify. The resulting lambda instance will then be silently assignable to any lambda variable whose return type is a subtype, since lambda return types are covariant.
In the example above, the first lambda instance (line 7) is inferred as type () => Foo & { b: boolean }
, which is subsequently assigned to the variable callback: () => Foo
on line 3, which is allowed because Foo & { b: boolean }
is a supertype of Foo
. In line 12 we fix this by preventing TypeScript from inferring a supertype.
The following article was very useful when writing this plugin:
Writing custom TypeScript ESLint rules: How I learned to love the AST
FAQs
Ensures explicit return types on functions and lambdas that return object literals.
The npm package eslint-plugin-return-types-object-literals receives a total of 114 weekly downloads. As such, eslint-plugin-return-types-object-literals popularity was classified as not popular.
We found that eslint-plugin-return-types-object-literals demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.