Skip to content

Rewrite imports with ".ts" extension to ".js" to support Nodejs's "--experimental-strip-types"Β #59597

Closed
@alshdavid

Description

@alshdavid

πŸ” Search Terms

#55346

βœ… Viability Checklist

⭐ Context

Nodejs is shipping built-in TypeScript support for local & development projects, where distributing for production still need to compile typescript sources to javascript for them to work.

This can be used in version >=22.6.0 behind the --experimental-strip-types flag.

A point of contention is that the Nodejs TypeScript transpiler relies on importing TypeScript sources using the .ts file extension.

Example;

// node --experimental-strip-types ./index.ts
// index.ts
import * as foo from './foo.ts'

While we can use the new Nodejs flag to run local TypeScript sources during development with .ts file extensions and tsconfig.json#compilerOptions.allowImportingTsExtensions: true; The TypeScript compiler is no longer capable of producing a valid output to run in Nodejs using this source code.

⭐ Discussion

In previous issues, members of the TypeScript team have stated that rewriting imports is out of scope for TypeScript and will not be implemented.

Has this stance changed in light of the newly added TypeScript support in Nodejs?

I am aware that the support status is experimental so Nodejs will make changes before it rolls out generally but it looks like this particular decision is not likely to change

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions