Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CraigMacomber opened this issue May 29, 2024 · 0 comments
Open
Assignees
Labels
Bug A bug in TypeScript

Comments

@CraigMacomber
Copy link

CraigMacomber commented May 29, 2024

🔎 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 #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.

CraigMacomber added a commit to microsoft/FluidFramework that referenced this issue Jun 4, 2024
## Description

microsoft/TypeScript#56718 was fixed, but does
not fix our issue so
microsoft/TypeScript#58688 was filed and is
now referenced.

Also a few minor cleanups in the file I saw while working on it.
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 14, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.6.0 milestone Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants