Skip to content

More actionable "must have annotation" message - #35839

Merged
Daniel Rosenwasser (DanielRosenwasser) merged 4 commits into
masterfrom
mustHaveAnnotationMessage
Jan 8, 2020
Merged

More actionable "must have annotation" message#35839
Daniel Rosenwasser (DanielRosenwasser) merged 4 commits into
masterfrom
mustHaveAnnotationMessage

Conversation

@DanielRosenwasser

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 => { }

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

2 participants