Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-typescript-non-null-assertion-runtime

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-typescript-non-null-assertion-runtime

## Summary

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-typescript-non-null-assertion-runtime

Summary

TypeScript has non-null-assertion to assert some expression is not nullable.
But it's a type only feature. Which means nothing will happend if the non-nullable value is nullable. It's a little hard to call it an assertion.

This plugin will adds runtime assert into all TypeScript non-null-assertion. And also we can add some additional easily.

With runtime assertion, we may find bugs as early as possible.

Install

  1. Run yarn add babel-plugin-typescript-non-null-assertion-runtime --dev
  2. Setup your babel config file. You can see using-a-plugin

Example

If we have below code:

const a = {
    b: 1,
};

a!.b = 1;
a.b! = 2;
const c = a!.b;
const d = a.b!;

And it will transform to:

function _nonNull(expr, message = "NonNull assertion failed") {
  if (expr === undefined || expr === null) {
    throw new Error(message);
  }

  return expr;
}

const a = {
  b: 1,
};
_nonNull(a).b = 1;
a.b! = 2;

const c = _nonNull(a).b;

const d = _nonNull(a.b);

Options

  • assertFunctionName: optional, name of assert function.
  • assertMessage: optional, error message of assert.
  • errorMessageIncludeSource: optional, include assert expression into error message.

FAQs

Package last updated on 29 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc