Skip to content

Conversation

@DanielRosenwasser
Copy link
Member

Fixes #35838

~~~~~~
!!! error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.
!!! related TS2728 tests/cases/conformance/controlFlow/assertionTypePredicates1.ts:144:11: 'assert' is declared here.
!!! related TS2782 tests/cases/conformance/controlFlow/assertionTypePredicates1.ts:144:11: 'assert' needs an explicit type annotation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I understand, this error was previously incorrect and is now still incorrect. the real problem is that we can't use asserts with arrow functions, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the arrow function is fully annotated, but the assert declaration itself needs to be annotated. It's very stupid.

- const assert = (value: unknown): asserts value => { }
+ const assert: (value: unknown) => asserts value = (value: unknown): asserts value => { }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or "better"

- const assert = (value: unknown): asserts value => { }
+ const assert: (value: unknown) => asserts value = value => { }

@DanielRosenwasser DanielRosenwasser merged commit 78748c0 into master Jan 8, 2020
@DanielRosenwasser DanielRosenwasser deleted the mustHaveAnnotationMessage branch January 8, 2020 00:46
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion function error messages are unactionable and unclear

3 participants