Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #7963
Closed
Open
Issue created Nov 11, 2019 by Administrator@rootContributor

TypeScript 3.7 Assertion Functions

Created by: jeremyBanks

#7940 (closed) (TypeScript 3.7 support) was closed as a dupe of #7431 (closed) (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.
Assignee
Assign to
Time tracking