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
{{ message }}
Repository navigation
Incorrect type inferrence for default-initialized parameters and noImplicitAny #36052
// No errorconstf1=(debug=true)=>false;// Error, but shouldn't be -- contextual type from 'Function'// shouldn't have negative effects hereconstf2: Function=(debug=true)=>false;
This is actually working as intended. For f1 it is meaningful to infer from the initializer because the inferred type will constrain arguments that can be passed for debug. But for f2 we've already established that the type is Function. Thus, anything we infer for debug will be disregarded, and we have no idea what type of arguments will actually be passed (and keep in mind that the default value only kicks in when we're passed an undefined).
Activity
RyanCavanaugh commentedon Jan 7, 2020
ahejlsberg commentedon Jan 24, 2020
This is actually working as intended. For
f1it is meaningful to infer from the initializer because the inferred type will constrain arguments that can be passed fordebug. But forf2we've already established that the type isFunction. Thus, anything we infer fordebugwill be disregarded, and we have no idea what type of arguments will actually be passed (and keep in mind that the default value only kicks in when we're passed an undefined).It's a similar discussion to here #30840 (comment).
typescript-bot commentedon Jan 26, 2020
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
ahejlsberg commentedon Jan 28, 2020
Having thought about it some more, I now agree that this is a bug. #36476 has the fix.