Issue
Given this code
export interface ICollectionService {
get(id: string): Promise<Collection | null>;
}
const collection = await collectionService.get(collectionAddress);
Now my collection variable showing in the IDE is Collection type
Not Collection | null as I expected.
Not sure if this has something to do with the eslint?
Here is my .eslintrc.js
module.exports = {
env: {
browser: true,
es2021: true
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
overrides: [],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
rules: {}
};
Solution
You need to set the compilerOptions.strictNullChecks flag in the tsconfig.json to true.
{
"compilerOptions": {
"strictNullChecks": true
}
}
The default value of compilerOptions.strictNullChecks is false
Answered By - vighnesh153
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.