microsoft / microsoft/TypeScript
[TS 5.4.0-beta] .d.ts emit adding an inline type import instead of utilising existing import
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
declaration emit inline type import resolution
🕗 Version & Regression Information
- This changed between versions 5.3.3 and 5.4.0-beta
- This changed in PR #56857
⏯ Playground Link
💻 Code
// @declaration
// @showEmit
// @showEmittedFile: app/navigator/widget-factory.d.ts
// @filename: lib/index.d.ts
import * as DefaultExport from "./internal/default_exports";
export { DefaultExport as default };
export * as BaseWindow from "./internal/windows/basewindow.d.ts";
// @filename: lib/internal/default_exports.d.ts
export { default as BaseWindow } from "./windows/basewindow";
// @filename: lib/internal/windows/basewindow.d.ts
interface BaseWindow {}
export interface BaseWindowConstructor {}
declare const BaseWindow: BaseWindowConstructor;
export default BaseWindow;
// @filename: lib-utils/shared-types/widget-config.d.ts
import type UI from "../../lib/index";
export interface WidgetFactory {
instantiator(parentWindow: UI.BaseWindow): void;
}
// @filename: app/navigator/widget-factory.ts
import {WidgetFactory} from "../../lib-utils/shared-types/widget-config";
declare const instantiator: WidgetFactory['instantiator'];
// 5.3: __synthetic_export_lib_1.BaseWindow.default
// 5.4: import("../../lib/internal/default_exports").BaseWindow
export default Object.freeze({
instantiator
});
// Our tools inject this before we pass the file to TS.
import type * as __synthetic_export_lib_1 from "../../lib/index";
🙁 Actual behavior
// app/navigator/widget-factory.d.ts
declare const _default: Readonly<{
instantiator: (parentWindow: import("../../lib/internal/default_exports").BaseWindow) => void;
}>;
export default _default;
import type * as __synthetic_export_lib_1 from "../../lib/index";
🙂 Expected behavior
// app/navigator/widget-factory.d.ts
declare const _default: Readonly<{
instantiator: (parentWindow: __synthetic_export_lib_1.BaseWindow.default) => void;
}>;
export default _default;
import type * as __synthetic_export_lib_1 from "../../lib/index";
Additional information about the issue
More background in previous conversation around this: #38111 and this public blog post: https://www.bloomberg.com/company/stories/10-insights-adopting-typescript-at-scale/
The JavaScript runtime we are using TypeScript on is not based on npm style packages (no node_modules resolution or package.json manifest). For the .d.ts that we publish to be able to work consistently across different versions it's important that the inter-package import paths only resolve to the 'public' files and not internal implementation .d.ts files.
To encourage TypeScript to pick these safer paths when emitting .d.ts we add unused imports to the bottom of each file before passing them to the TS compiler.
In general this is still working in 5.4.0-beta, however during our testing at least 8 packages's .d.ts emit regressed with the beta. The playground above re-creates one of these.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず playground の再現から始め、特に app/navigator/widget-factory.ts、lib-utils/shared-types/widget-config.d.ts、lib/index.d.ts を確認し、その後 PR #56857 による declaration emit の変更を追ってください。生成された app/navigator/widget-factory.d.ts が internal/default_exports への inline の import path を追加するのではなく、__synthetic_export_lib_1.BaseWindow.default を再利用すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100