-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Per #9998 and its many offshoots, we have problems analyzing code like this
let x: string | number = "OK";
mystery(() => {
x = 10;
});
if (x === 10) { // Error, we believe this to be impossible
}
The problem is that we don't know if mystery
invokes its argument "now" or "later" (or possibly even never!).
The converse problem appears during reads:
let x: string | number = ...;
if (typeof x === 'string') {
// Error, toLowerCase doesn't exist on string | number
let arr = [1, 2, 3].map(n => x.toLowerCase());
}
Proposal is to allow some form of indicating that the function is invoked immediately, e.g.
declare function mystery(arg: immediate () => void): void;
This would "inline" the function body for the purposes of flow control analysis
yortus, tinganho, kitsonk, HerringtonDarkholme, threehams and 142 morejsejcksn, relu91, walkerburgin, SlurpTheo, odinho and 5 moresyuilomjrlowe, lo1tuma, Zzzen, icecream17, ashercarson and 9 more
Metadata
Metadata
Assignees
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript