You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our new checks will now yell at you for forgetting to initialize count and not informing us that count could be undefined.
Even if you initialize it at the wrong point.
functioncountLines(text: string[]){letcount: number;for(constlineoftext){count=0;// not good enough - this loop might never execute!if(line.length!==0){count=count+1;}}returncount;}
countLines has type number | undefined since you implicitly returned undefined.
Assignments as a new type guard point
declarefunctiongetNumberOrString(): number|string;varx=getNumberOrString();// has type 'number | string'if(typeofx==="string"){x;// has type 'string'x=1000;// still okay to assign a 'number'x;// has type 'number'}
Shortcomings
Array accesses
Technically we should be introducing undefined from array indexing, but this would be such a massive pain for users that we can't consider this path.
Variable capture in closures
We don't track usage of a variable's use within a function.
functionuh_oh(){returns.slice();}vars: string;uh_oh();// no error.
Potential for other work
Could we use this logic for checking for this before super, etc.?
Yes!
The text was updated successfully, but these errors were encountered:
this
-types for functions (#6739)this
for the scope of a function.this
is assumed to have the type of the class itself.this
.Strict
this
checksmaster.
.d.ts
files.this
checking.this
checking.this
.No implicit
this
noImplicitAny
?noImplicitThis
would not be umbrella'd.Library modularization (#6974)
Background: hard to say what environments will have what at runtime.
Our libraries try to be all-encompassing.
The workaround has been to modify
lib.d.ts
on your own, but nobody wants to do that.Current solution: granular libraries.
What about ambient decorators?
You have
es6.array.d.ts
,es6.collection.d.ts
, etc.New
--lib
flag, takes a list of options.es6
as the lib as an aggregate flag (includees6.*.d.ts
).es7.d.ts
for all one functions that were added to ES7.--target
toggles the default if--lib
isn't specified.--target es2015
still includeslib.es6.d.ts
.So by default, you get the ES3 lib?
lib.d.ts
?--lib es5
and add from there on.--lib es5,dom
.--lib node
.What about granular transformations?
async/await
because Node has it, but as soon as you try to do ES6 emit, you run into problems like Node not supporting destructuring.Conditional compilation stuff
Granularity
Control Flow Analysis For Everything (#2388)
Consider
Our new checks will now yell at you for forgetting to initialize
count
and not informing us thatcount
could beundefined
.Even if you initialize it at the wrong point.
We also infer correctly from falling through.
countLines
has typenumber | undefined
since you implicitly returnedundefined
.Assignments as a new type guard point
Shortcomings
Array accesses
Technically we should be introducing
undefined
from array indexing, but this would be such a massive pain for users that we can't consider this path.Variable capture in closures
We don't track usage of a variable's use within a function.
Potential for other work
this
beforesuper
, etc.?The text was updated successfully, but these errors were encountered: