Skip to content

Support stripping TypeScript’s CJS syntax #63977

@remcohaszing

Description

@remcohaszing

What is the problem this feature will solve?

Currently it’s not possible to use Node.js type stripping to load a TypeScript CJS file:

import fs = require('fs')
export = fs

This is equivalent to the following JavaScript:

var fs = require('fs')
module.exports = fs

You could use the JavaScript style syntax, but then it’s no longer proper TypeScript. So you miss out on type checking features.

What is the feature you are proposing to solve the problem?

The import and export statements are long enough, that they can be replaced with whitespace and a temporary variable. Some helper code can be added to the end of the file. The code above can be replaced with:

// `import` → `var   `
var    fs = require('fs')
// `export` → `var xp`
var xp = fs
// Helper code
module.exports = xp

What alternatives have you considered?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions