- Notifications
You must be signed in to change notification settings - Fork0
TsLint rules preventing undefined leaks in strictNullChecks mode
License
alhugone/tslint-strict-null-checks
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
TypeScript (latest release 2.4.1) strictNullChecks is not reliable. It does not work as it should at least in two basic cases. It does not enforce initialization of varaiables and properties, so they will beundefined, even ifundefined is not in the domian.
Code that (should not) compiles in strictNullChecks:
classX{publicx:number;}letx:number;functionf():number{returnx;}letm:number=f();letc:X=newX();console.log(`m:${m}`);console.log(`c.x:${c.x}`);
results in:
m: undefinedc.x: undefined
With ts-strict-null-checks You will be warned about not initialized variables and properties.
Install from npm to your devDependencies:
npm install --save-dev tslint-strict-null-checks
Configure tslint to use the tslint-strict-null-checks folder. Add the following path to therulesDirectory setting in yourtslint.json file:
{"rulesDirectory": ["node_modules/tslint-strict-null-checks/rules" ],"rules": {... }}Enforces initialization of variables and properties, whenundefined is not in their domain.
"no-uninitialized": [true,"variables","properties"]
If You find any gap whereundefined can be smuggled pleaseopen an issue.
Please contribute usingGithub Flow. Create a branch, add commits, andopen a pull request.
About
TsLint rules preventing undefined leaks in strictNullChecks mode
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.