Skip to content

Support .ts module imports in TypeSpec source files#10956

Open
Copilot wants to merge 10 commits into
mainfrom
copilot/support-importing-typescript-files
Open

Support .ts module imports in TypeSpec source files#10956
Copilot wants to merge 10 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: 7ddf370

@microsoft-github-policy-service microsoft-github-policy-service Bot added the stale Mark a PR that hasn't been recently updated and will be closed. label Jun 25, 2026
@timotheeguerin

Copy link
Copy Markdown
Member

@copilot add changelog

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add changelog

Added the changelog entry in 87a8aedc3 under .chronus/changes/copilot-support-importing-typescript-files-2026-5-25-13-53-33.md.

@timotheeguerin timotheeguerin marked this pull request as ready for review June 26, 2026 18:05
@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - feature ✏️

Support importing .ts decorator modules from TypeSpec source files.

@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

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 stale Mark a PR that hasn't been recently updated and will be closed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support importing TypeScript files from TypeSpec

2 participants