Disallow undefined
for keeping structure.
The following will all be incorrect usage:
const foo = { x: 123, y: undefined };
The following will all be correct usage:
const foo: { x: number, y?: number } = { x: 123 };
We made it to keep this TypeScript styleguide's null-vs-undefined
.
yarn add -D eslint-plugin-use-optional-annotation
# or npm i -D eslint-plugin-use-optional-annotation
Set .eslintrc
following
plugins: [
'use-optional-annotation' // add to `plugins` arrays final element.
],
// ...
rules: {
'use-optional-annotation/use-optional-annotation': 'error'
}