Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript 3.7 assertion signature syntax not working #503

Closed
alangpierce opened this issue Jan 13, 2020 · 0 comments · Fixed by #504
Closed

TypeScript 3.7 assertion signature syntax not working #503

alangpierce opened this issue Jan 13, 2020 · 0 comments · Fixed by #504

Comments

@alangpierce
Copy link
Owner

This code snippet crashes when it should work and remove the asserts condition:

function assert(condition: any, msg?: string): asserts condition {
    if (!condition) {
        throw new AssertionError(msg)
    }
}

Playground link

Looks like when I ported the changes from Babel, I only tested the asserts x is T case rather than just asserts x.

alangpierce added a commit that referenced this issue Jan 13, 2020
Fixes #503

The previous code didn't handle the basic case `asserts x`, which I just
overlooked when backporting Babel parser changes. The new code has a special
case for that and conditionally tells the caller whether to parse a type
afterward. I also made the contract a little simpler; it either fully parses the
return type or it doesn't.
alangpierce added a commit that referenced this issue Jan 13, 2020
Fixes #503

The previous code didn't handle the basic case `asserts x`, which I just
overlooked when backporting Babel parser changes. The new code has a special
case for that and conditionally tells the caller whether to parse a type
afterward. I also made the contract a little simpler; it either fully parses the
return type or it doesn't.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant