Skip to content

Support .ts module imports in TypeSpec source files#10956

Draft
Copilot wants to merge 8 commits into
mainfrom
copilot/support-importing-typescript-files
Draft

Support .ts module imports in TypeSpec source files#10956
Copilot wants to merge 8 commits into
mainfrom
copilot/support-importing-typescript-files

Conversation

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

TypeSpec imports currently recognize .tsp, .js, and .mjs, which prevents directly importing TypeScript decorator modules. This change adds first-class .ts import recognition so TypeSpec routes those imports through the existing JS module loading path.

  • Compiler import classification

    • Updated getSourceFileKindFromExt to classify .ts as "js" in packages/compiler/src/core/source-file.ts.
    • This enables import "./decorators.ts"; to flow through the same runtime import path as existing JS imports.
  • Import checker coverage

    • Added .ts import tests in packages/compiler/test/checker/imports.test.ts, mirroring existing .js coverage:
      • relative .ts import
      • parent-folder relative .ts import
  • Compiler e2e coverage

    • Added an end-to-end scenario in packages/compiler/test/e2e/scenarios/import-relative-ts/ and wired it into packages/compiler/test/e2e/scenarios/scenarios.e2e.ts.
    • The scenario verifies a TypeSpec source importing ./decorators.ts compiles successfully.
  • Language docs

    • Updated website/src/content/docs/docs/language-basics/imports.md to list .ts as a supported explicit file extension for imports.
import "./my-decorators.ts";

@myDecorator
model A {}

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added compiler:core Issues for @typespec/compiler meta:website TypeSpec.io updates labels Jun 10, 2026
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for importing TypeScript files from TypeSpec Support .ts module imports in TypeSpec source files Jun 10, 2026
Copilot AI requested a review from timotheeguerin June 10, 2026 20:12
@timotheeguerin

Copy link
Copy Markdown
Member

@copilot can we have one e2e test here also?

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Comment thread packages/compiler/test/e2e/scenarios/import-relative-ts/decorators.ts Outdated
Copilot AI and others added 3 commits June 10, 2026 21:43
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Comment thread packages/compiler/test/e2e/scenarios/import-relative-ts/decorators.ts Outdated
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot can we have one e2e test here also?

Added an e2e scenario coverage for this in b35f639e (import-relative-ts + scenarios.e2e.ts).

@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@10956

commit: 80f4f9f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support importing TypeScript files from TypeSpec

2 participants