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 Functions #7963

Closed
jeremyBanks opened this issue Nov 11, 2019 · 3 comments · Fixed by #8024
Closed

TypeScript 3.7 Assertion Functions #7963

jeremyBanks opened this issue Nov 11, 2019 · 3 comments · Fixed by #8024
Assignees
Milestone

Comments

@jeremyBanks
Copy link

#7940 (TypeScript 3.7 support) was closed as a dupe of #7431 (optional chaining and nullary coalescing support). However, TypeScript 3.7 had another syntax change that wasn't included in that: assertion functions. Unlike the other syntax changes, this isn't being standardized as part of regular JavaScript, which might be why there doesn't seem to be a Babel plugin for it.

I've been looking forward to using this feature. Will it be possible to support it in CRA?

Example Output

mkdir example;
cd example;
npx create-react-app . --typescript;
echo '
function assertIsString(val: any): asserts val is string {
    if (typeof val !== "string") {
        throw new AssertionError("Not a string!");
    }
}
' > src/App.tsx;
yarn build;
yarn run v1.17.3
$ react-scripts build
Creating an optimized production build...
=============

WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=3.2.1 <3.7.0

YOUR TYPESCRIPT VERSION: 3.7.2

Please only submit bug reports when using the officially supported version.

=============
Failed to compile.

./src/App.tsx
SyntaxError: /home/jeremy/example/src/App.tsx: Unexpected token, expected "{" (1:43)

> 1 | function assertIsString(val: any): asserts val is string {
    |                                            ^
  2 |     if (typeof val !== "string") {
  3 |         throw new AssertionError("Not a string!");
  4 |     }


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@ianschmitz
Copy link
Contributor

I'll look into this and get back to you whether it's supported.

@ianschmitz
Copy link
Contributor

Looks like this should be supported via Babel and typescript-eslint

Here's the reference for TypeScript 3.7 support in Babel: https://github.com/babel/babel/milestone/29?closed=1. Looks like we may have to bump the packages once more before releasing here as one PR was merged only hours ago.

Here's typescript-eslint: typescript-eslint/typescript-eslint#1045

@SQReder
Copy link

SQReder commented Nov 22, 2019

@ianschmitz look like both babel and typescript-eslint done with referenced PRs. Any updates for CRA?
We want to use assertion feature and AFAIK react-scripts is the last stopper.

@lock lock bot locked and limited conversation to collaborators Nov 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants