
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
eslint-plugin-expect-type
Advanced tools
ESLint plugin with $ExpectType, $ExpectError and $ExpectTypeSnapshot type assertions
ESLint plugin with $ExpectType and $ExpectError type assertions
Make sure you have TypeScript and @typescript-eslint/parser installed, then install the plugin:
npm i -D eslint-plugin-expect-type
Please also make sure the following packages are also installed:
npm i -D eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser
Please add the following options to your .eslintrc
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": ["eslint-plugin-expect-type"],
"extends": ["plugin:eslint-plugin-expect-type/recommended"]
}
Rule severity could be configured as follows
{
"rules": {
"expect-type/rule": "error"
}
}
Note: Make sure to use eslint --ext .js,.ts
since by default eslint
will only search for .js files.
A test file should be a piece of sample code that tests using the library. Tests are type-checked, but not run. To assert that an expression is of a given type, use $ExpectType. To assert that an expression causes a compile error, use $ExpectError. (Assertions will be checked by the expect lint rule.)
(https://github.com/Microsoft/dtslint#write-tests)
import foo from 'lib-to-test'; // foo is (n: number) => void
// $ExpectType void
foo(1);
// Can also write the assertion on the same line.
foo(2); // $ExpectType void
// $ExpectError
foo('bar');
Uses snapshot saved in file as expected type for expression.
Example:
foo.test.ts
// $ExpectTypeSnapshot Foo
const Foo = {
a: 1,
n: 17,
} as const;
By running eslint --fix
the following file will be created in the folder of foo.test.ts
:
type-snapshots/foo.test.ts.snap.json
By running eslint
snapshot type will be matched with actual type and Error will be emitted in case types don't match.
eslint --fix
FAQs
ESLint plugin with ^? Twoslash, $ExpectError, and $ExpectType type assertions. 🧩
The npm package eslint-plugin-expect-type receives a total of 5,974 weekly downloads. As such, eslint-plugin-expect-type popularity was classified as popular.
We found that eslint-plugin-expect-type demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.