TypeScript emits d.ts file that is invalid for complex mapped type.

オープン
#58,688 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

@weswigham がすでに取り組んでいます。

2024年6月14日 から。

評価

この issue はまだ評価されていません。

説明

Bug Domain: Declaration Emit
🔎 Search Terms

d.ts emit type error

🕗 Version & Regression Information

This is a compile error when consuming a d.ts file emitting by the same version and configuration of TypeScript
This in 3.5.1, 4.0.5, 5.4.5 and 5.5.0-dev.20240528, but NOT in 3.3.3

⏯ Playground Link

https://www.typescriptlang.org/play/?module=1&ts=5.4.5&ssl=11&ssc=1&pln=1&pc=1#code/KYDwDg9gTgLgBAMwK4DsDGMCWEVwIYAmeYMAoikgLYA8AKuVXKDMCgQM5wBKwa0B1djCiYUAcwA0cISPEA+OQAoAUAEo4Ab2UBIGAE8wwOAAU8sAIxwAvJp3aA2sagRDsPXFFwA1sD0QEcPQUlAC6AFxwiupWcoEMlI7OrvohOgC+ANw6fChCiHgY0HoA8kjwNlHWsVra2lDAMEhQuIoADPicqF4oEADuuHic+ob++YVQJWVwAGQmZjDmqvbtg3BdPf0d3r6jQVQhlelZdQ1NuAgFMEWlMFlpykA

💻 Code
export function adaptEnum<TEnum extends Record<string, string>>(
) {
	type Part1 = {
		[Property in keyof TEnum]: () => TEnum[Property]
	};
	const factoryOut = () => {
		return (0 as unknown as typeof factoryOut & Part1)[0 as unknown as keyof TEnum]() 
	};
	return factoryOut;
}
🙁 Actual behavior

Emits:

export declare function adaptEnum<TEnum extends Record<string, string>>(): () => TEnum[string] | TEnum[number] | TEnum[symbol];

Which Errors:
Type 'number' cannot be used to index type 'TEnum'.(2536)

🙂 Expected behavior

I expect TypeScript to either error when trying to emit a d.ts file, or generate a valid d.ts file it can consume without error.

Additional information about the issue

This issue report is derived from minimizing the same code that produced https://github.com/microsoft/TypeScript/issues/56718 (which is now fixed) and is similar to that issue. The same workaround I have from that case still works, so this isn't blocking anything except removing that workaround.

主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。