Skip to content

Add never helper function#18287

Merged
3 commits merged into
masterfrom
never
Sep 8, 2017
Merged

Add never helper function#18287
3 commits merged into
masterfrom
never

Conversation

@ghost

@ghost ghost commented Sep 6, 2017

Copy link
Copy Markdown

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 aozgaa, mhegazy and weswigham September 6, 2017 21:01
Comment thread src/compiler/core.ts Outdated
return (arg: T) => f(arg) && g(arg);
}

export function never(never: never): never {

@weswigham weswigham Sep 6, 2017

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.

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.

@weswigham weswigham left a comment

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.

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