Typescript: allow voluntary .ts suffix for import paths

Created on 25 Mar 2020  路  3Comments  路  Source: microsoft/TypeScript

Search Terms

.ts
suffix
imports
extension

Suggestion

Typescript doesn't recognize file imports with .ts suffix.
Allow voluntary .ts to be added to import paths.

Use Cases

It seems right to be able to use a correct path to a file without magic resolution.
This would help to align with deno which uses mandatory suffixes o files.

Examples

let
import a from "path/to/a.ts"
behave the same as
import a from "path/to/a"

Checklist

My suggestion meets these guidelines:

  • [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [x] This wouldn't change the runtime behavior of existing JavaScript code
  • [x] This could be implemented without emitting different JS based on the types of the expressions
  • [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [x] This feature would agree with the rest of TypeScript's Design Goals.
In Discussion Suggestion

Most helpful comment

After some more research I wonder if that behavior could even be more guided by a compiler option like --noImplicitSuffix.
That would be in alignment with --noImplicitAny and give the developer the choice, yet push for a valid, not "magical" resolved path if not set.

What are your thoughts on that?

All 3 comments

After some more research I wonder if that behavior could even be more guided by a compiler option like --noImplicitSuffix.
That would be in alignment with --noImplicitAny and give the developer the choice, yet push for a valid, not "magical" resolved path if not set.

What are your thoughts on that?

35148

35148

Read through the above and it seems to boil down to multiple build targets with different file extensions throws a wrench in things when supporting using the file extensions on imports. Where it diverges in my mind, and hopefully @Jack-Works you can illuminate this a bit, is that we'd be importing .ts extensions which would have to be rewritten anyways.

Was this page helpful?
0 / 5 - 0 ratings