强迫症患者请教个ts语法的问题

我的看法是,如果不能保证引用链中一直保持非空的话,即使 ?. 必然会进行严格判断,那也是出于严谨考虑;当然,如果能保证非空的情况下的确使用ts中的非空断言可能会更合适

这不对吧 定义的时候已经非空断言 使用的时候还要判断非空

project folder / tsconfig.json

{

/* Base configuration. Do not edit this field. */

“extends”: “./temp/tsconfig.cocos.json”,

"compilerOptions": {

"target": "ES2015",

"module": "ES2015",

"strict": true,  

"strictNullChecks": false,  <--- add

"types": [

  "./temp/declarations/cc",

  "./temp/declarations/jsb",

  "./temp/declarations/cce.env"

],

"experimentalDecorators": true,

"isolatedModules": true,

"moduleResolution": "node",

"noEmit": true,

"forceConsistentCasingInFileNames": true

}

/* Add your custom configuration here. */

}

1赞