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
getResults1([]);getResults1({data: []});getResults2([]);getResults2({data: []});typeResult={value: string}typeResults=Result[];functionisResponseInData<T>(value: T|{data: T}): value is {data: T}{returnvalue.hasOwnProperty('data');}functiongetResults1(value: Results|{data: Results}): Results{// error TS2322: Type 'Results | {data: Results}' is not assignable to 'Results'returnisResponseInData(value) ? value.data// value: {data: Results}
: value;// value: Results | {data: Results} !!}functionisPlainResponse<T>(value: T|{data: T}): value is T{return!value.hasOwnProperty('data');}functiongetResults2(value: Results|{data: Results}): Results{// GoodreturnisPlainResponse(value) ? value// value: Results
: value.data;// value: {data: Results}}
Expected behavior:
Expected both getResults1 and getResults2 to compile fine, as they did in typescript@2.0.0 and typescript@1.8.10.
Actual behavior: getResults1 doesn't compile, because value's type doesn't get narrowed in versions from typescript@2.0.2 forward (still an issue in 2.2.0-dev.20161114).
The text was updated successfully, but these errors were encountered:
TypeScript Version: >= 2.0.2
Code
Expected behavior:
Expected both
getResults1
andgetResults2
to compile fine, as they did in typescript@2.0.0 and typescript@1.8.10.Actual behavior:
getResults1
doesn't compile, becausevalue
's type doesn't get narrowed in versions from typescript@2.0.2 forward (still an issue in 2.2.0-dev.20161114).The text was updated successfully, but these errors were encountered: