Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow import .ts and .tsx, New --emitExtension compiler options #35148

wants to merge 14 commits into
base: master


Copy link

Jack-Works commented Nov 17, 2019

Related: #8529, #27957

Fixes #30076, #18442, #16577, #33306

See also: #35163 (browser style module resolution when finding type declarations)

See also: Node.js new ESModule support:

Allow import .ts and .tsx file.

Deno is a new JS environment and it has a built in TypeScript compiler. It is not using node style import module specifiers but browser styles (need explicit extension name).

This PR changes the checker, now ImportDeclaration with endings of .ts and .tsx is no longer a TypeError.
Import a .d.ts is still a TypeError.

New --emitExtension compiler options.

This PR introduce a new compiler options --emitExtension. This allows to emit .mjs, .es6.js, .es or any extension user specifies.


{ compilerOptions: { emitExtension: ".mjs" } }

Sourcefile: index.ts

import type from './a.ts'
import type2 from './b.mjs'
console.log(type, type2)

Emit: index.mjs

import type from './a.mjs'
import type2 from './b.mjs'
console.log(type, type2)


According to #35163 (comment) maybe --emitExtension should be default to .js when the target module system is es module

Jack-Works added 12 commits Nov 16, 2019
@Jack-Works Jack-Works marked this pull request as ready for review Nov 17, 2019

This comment has been minimized.

Copy link

Jack-Works commented Nov 17, 2019

help wanted! how can I accept new baseline for this test?

         fourslash tests
             fourslash test completionListIsGlobalCompletion.ts runs correctly:
     Error: At 1: Expected no completions
      at TestState.raiseError (src/harness/fourslash.ts:489:19)
      at TestState.verifyCompletionsWorker (src/harness/fourslash.ts:808:61)
      at TestState.verifyCompletions (src/harness/fourslash.ts:770:26)
      at Verify.completions (src/harness/fourslash.ts:3976:28)
      at eval (eval at runCode (src/harness/fourslash.ts:3290:23), <anonymous>:37:8)
      at runCode (src/harness/fourslash.ts:3291:13)
      at runFourSlashTestContent (src/harness/fourslash.ts:3271:9)
      at Object.runFourSlashTest (src/harness/fourslash.ts:3256:9)
      at Context.<anonymous> (src/testRunner/fourslashRunner.ts:56:39)
      at processImmediate (internal/timers.js:439:21)

@Jack-Works Jack-Works mentioned this pull request Nov 18, 2019
1 of 6 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.