Poor support for TypeScript not-null assertions
See original GitHub issueBug Report
Current Behavior
TypeScript’s postfix !
not-null assertion isn’t supported in various commonly used scenarios, such as a! *= 1;
and a! / 10
Input Code
function doSomething(a: number | null) {
// SyntaxError: src/test.ts: Unexpected token =
a! *= 1;
// SyntaxError: src/test.ts: Unterminated regular expression
return a! / 2;
}
Expected behavior/code No error
Babel Configuration (.babelrc, package.json, cli command)
{
"plugins": [
"@babel/plugin-transform-typescript"
]
}
Environment
- Babel version(s): v7.0.0-beta.47
- Node/npm version: Node 10.1.0 / npm 6
- OS: macOS 10.13.4
- Monorepo ?
- How you are using Babel:
cli
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
TypeScript non-null assertion operator does not work
I have a type with a conditional property (in this case 'b') type tp1 = {a: string, b?: Array<number>};. I create an object...
Read more >Documentation - TypeScript 2.0
Non-null assertion operator ... A new ! post-fix expression operator may be used to assert that its operand is non-null and non-undefined in...
Read more >Typescript - Tips & Tricks - Non-null assertion operator
This operator says to the compiler that the field isn't null or undefined but it's defined. type Person = { name: string; };...
Read more >Non-null assertions should not be used - SonarSource Rules
Using a non-null assertion (the !. operator) will lead to a runtime error if the optional does contain null or undefined . Even...
Read more >no-non-null-assertion | typescript-eslint
TypeScript's ! non-null assertion operator asserts to the type system that an expression is non-nullable, as in not null or undefined . Using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
a! = 2
has been fixed by https://github.com/babel/babel/pull/7888@existentialism
babylon@7.0.0-beta.47
, let me know if you need any configuration files from my project.Unexpected token, expected ";" (369:44)
Line 369 is:
const x = document.getElementById('foo')!;
Char 44 is
!
with 4 spaces in front of theconst
keyword.