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
The new assertions in control flow analysis (see #32695) feature fails to work when the assert function is defined as an arrow function (i.e. defined using const or let).
TypeScript Version: 3.7.0-dev.20190925
Search Terms:
Assertions in control flow analysis
Code
constassert0=(input: unknown): asserts input=>{}functionassert1(input: unknown): asserts input{}declareconstassert2: (input: unknown)=> asserts inputdeclarefunctionassert3(input: unknown): asserts inputconstinputFunction=(input: number)=>{}consttest=(x: unknown,y: unknown,z: unknown,w: unknown)=>{assert0(typeofx==="number")x// VSCode intellisense says the type of x is still unknown hereinputFunction(x)assert1(typeofy==="number")y// VSCode intellisense says y is number, which is expectedinputFunction(y)assert2(typeofz==="number")z// VSCode intellisense says z is number, which is expectedinputFunction(z)assert3(typeofw==="number")w// VSCode intellisense says w is number, which is expectedinputFunction(w)}
Expected behavior: x, y, z, w should all have the type number after the respective assertion.
Actual behavior: x remains as unknown. This behavior is exhibited both in VSCode's type preview (see here: https://i.imgur.com/04uJTor.png) and as a compile error when we call inputFunction(x). The tsc error output is shown below:
index.ts:12:19 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'number'.
12 inputFunction(x)
~
Found 1 error.
Playground Link:
Playground's "nightly" version doesn't support the asserts syntax.
Related Issues:
N/A
The text was updated successfully, but these errors were encountered:
The new assertions in control flow analysis (see #32695) feature fails to work when the assert function is defined as an arrow function (i.e. defined using
const
orlet
).TypeScript Version: 3.7.0-dev.20190925
Search Terms:
Assertions in control flow analysis
Code
Expected behavior:
x
,y
,z
,w
should all have the typenumber
after the respective assertion.Actual behavior:
x
remains asunknown
. This behavior is exhibited both in VSCode's type preview (see here: https://i.imgur.com/04uJTor.png) and as a compile error when we callinputFunction(x)
. Thetsc
error output is shown below:Playground Link:
Playground's "nightly" version doesn't support the
asserts
syntax.Related Issues:
N/A
The text was updated successfully, but these errors were encountered: