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
constfn=(options: {foo: 'BAR'})=>{};constfnOptions={foo: 'BAR'};// TS tells that "fnOptions" is not assignable to the "options" parameter.fn(fnOptions);// Although following invocation doesn't raise errors.fn({foo: 'BAR'});
Expected behavior:
When passing fnOptions to fn function inferred type of its foo property should be narrowed to "BAR".
Actual behavior:
At the time of fn invocation inferred type of fnOptions is {foo: string} which renders it not assignable to the options parameter.
There's no guarantee at any given fn(fnOptions) call that someone hasn't written fn.foo = 'baz'; after the object was initialized. Search for "string literal widening" to see other issues on this.
TypeScript Version: 2.8.0-dev.20180308
Search Terms:
Code
Expected behavior:
When passing
fnOptions
tofn
function inferred type of itsfoo
property should be narrowed to"BAR"
.Actual behavior:
At the time of
fn
invocation inferred type offnOptions
is{foo: string}
which renders it not assignable to theoptions
parameter.Playground Link: link
Related Issues: #17943
The text was updated successfully, but these errors were encountered: