question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Poor support for TypeScript not-null assertions

See original GitHub issue

Bug 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:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
nicolo-ribaudocommented, May 17, 2018
0reactions
CoskunSunalicommented, May 21, 2018

@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 the const keyword.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found