鑒于此代碼
export interface ICollectionService {
get(id: string): Promise<Collection | null>;
}
const collection = await collectionService.get(collectionAddress);
現在我collection在 IDE 中顯示的變數Collection型別不是Collection | null我預期的。
不確定這是否與 eslint 有關?
這是我的.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: {}
};
uj5u.com熱心網友回復:
您需要在 to 中設定compilerOptions.strictNullChecks標志。tsconfig.jsontrue
{
"compilerOptions": {
"strictNullChecks": true
}
}
compilerOptions.strictNullChecks的默認值為false
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/511971.html
上一篇:./src/index.js找不到檔案:'App.js'與磁盤上的相應名稱不匹配:'.\src\components\Components'
