New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

bare-type-stripper

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bare-type-stripper

Heuristic lexer for stripping TypeScript type syntax to produce plain JavaScript

latest
Source
npmnpm
Version
0.1.7
Version published
Weekly downloads
19K
-0.87%
Maintainers
1
Weekly downloads
 
Created
Source

bare-type-stripper

Heuristic lexer for stripping TypeScript type syntax to produce plain JavaScript. Stripped regions are replaced with spaces so source positions and line numbers are preserved.

Usage

const strip = require('bare-type-stripper')

strip(`
  const x: number = 1
  function f<T>(xs: T[]): T { return xs[0] }
`).toString()

// '
//   const x         = 1
//   function f   (xs   )    { return xs[0] }
// '

API

See the bare-type-stripper reference.

What gets stripped

ConstructExample
Type annotationsconst x: number = 1
Type aliasestype Foo = number
Interfacesinterface Foo { x: number }
Type-only imports/exportsimport type { Foo } from 'mod'
Generics at declarationsfunction f<T>(x: T): T
Generics at call sitesfoo<number>()
Generic arrow functions<T>(x: T) => x
Type assertionsx as Foo, x satisfies Foo
Non-null assertionobj!.foo
Optional parameter markerfunction f(x?: T)
Definite assignmentlet x!: number
Class member modifierspublic, private, readonly, etc.
implements clausesclass C implements I
declare statementsdeclare const x: number
Overload signaturesfunction f(x: string): void
Abstract membersabstract foo(): void

What is left alone

  • Decorators - they emit runtime code and are valid JavaScript syntax.

What throws

Constructs with runtime semantics that a purely lexical stripper cannot reproduce are marked with the ERROR flag, and strip() throws a SyntaxError when it meets one:

  • enum / const enum declarations - they emit a runtime object.
  • namespace / module declarations with bodies - they emit runtime code.
  • Parameter properties - constructor(public x: number) implies a this.x = x assignment that stripping the modifier would silently lose.
  • Old-style angle-bracket type assertions (<Foo>expr) - indistinguishable from JSX, which is not supported.

Limitations

The stripper targets plain .ts sources; JSX (.tsx) is not supported and is reported as non-erasable syntax.

Threat model

bare-type-stripper is one of the addons Bare compiles into its binary, so it inherits Bare's threat model. See docs/threat-model.md for where this addon sits in it.

License

Apache-2.0

FAQs

Package last updated on 14 Sep 2026

Related posts