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
Assertion functions do not work when using arrow functions.
🔎 Search Terms
ts2775, arrow functions, assertion functions
🕗 Version & Regression Information
Assertion functions were introduced in 3.7. The behavior has been the same since that version.
This is the behavior in every version I tried, and I reviewed the FAQ for entries about it.
functionassertOne(val: unknown): asserts val is string{if(typeofval!=="string"){thrownewError("Not a string!");}}constassertTwo=(val: unknown): asserts val is string=>{if(typeofval!=="string"){thrownewError("Not a string!");}}functionmain(str: unknown){assertOne(str);// worksassertTwo(str);// "Assertions require every name in the call target to be declared with an explicit type annotation. (ts2775)"returnstr;}
🙁 Actual behavior
assertOne() works. assertTwo() (although nearly identical) shows the following type checking error:
Assertions require every name in the call target to be declared with an explicit type annotation. (ts2775)
🙂 Expected behavior
assertTwo() should not show any type checking error.
The text was updated successfully, but these errors were encountered:
Bug Report
Assertion functions do not work when using arrow functions.
🔎 Search Terms
ts2775, arrow functions, assertion functions
🕗 Version & Regression Information
Assertion functions were introduced in 3.7. The behavior has been the same since that version.
This is the behavior in every version I tried, and I reviewed the FAQ for entries about it.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
assertOne()
works.assertTwo()
(although nearly identical) shows the following type checking error:🙂 Expected behavior
assertTwo()
should not show any type checking error.The text was updated successfully, but these errors were encountered: