Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Sep 6, 2017

Moved out of #18154.
This would add a never function which both:

  • At compile-time, asserts that the type of the value is never.
  • At runtime, throws an error.

#18154 uses a function assertTypeIsNever but handles the value regardless.
I think @weswigham was going to add a similar function in one of his PRs.

@ghost ghost requested review from weswigham, aozgaa and mhegazy September 6, 2017 21:01
@@ -2628,4 +2628,8 @@ namespace ts {
export function and<T>(f: (arg: T) => boolean, g: (arg: T) => boolean) {
return (arg: T) => f(arg) && g(arg);
}

export function never(never: never): never {
Copy link
Member

@weswigham weswigham Sep 6, 2017

Choose a reason for hiding this comment

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

I think this should be in Debug and should be an assert, like assertNever. I also think that retaining the custom error messages which were at these sites prior to this is valuable; so it should have an (optional?) argument for the message. It should likely also defer to Debug.fail for throwing the error so it can pass the never asserting function as the stackCrawlMark so that there are not extra irrelevant stack frames in the error.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

The actual assertNever function is now merged with #18172. Once the merge conflict is resolved (they're identical except return vs throw), replacing the fails with assertNevers is good. 👍

@ghost ghost merged commit 409d659 into master Sep 8, 2017
@ghost ghost deleted the never branch September 8, 2017 21:22
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
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.

2 participants