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

Đang mở
#58,688 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@weswigham đang làm issue này rồi.

Từ ngày 14/6/2024.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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.

Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/TypeScript

Tất cả issue của microsoft/TypeScript

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.