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

typeof with identically named type and value causes invalid .d.ts output #58390

Closed
ssalbdivad opened this issue May 1, 2024 · 7 comments Β· Fixed by #58410
Closed

typeof with identically named type and value causes invalid .d.ts output #58390

ssalbdivad opened this issue May 1, 2024 · 7 comments Β· Fixed by #58410
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@ssalbdivad
Copy link

πŸ”Ž Search Terms

type, value, .d.ts, circular, circularity, invalid, output, declaration

πŸ•— Version & Regression Information

  • This changed between versions 5.4 and 5.5

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.5.0-dev.20240501#code/KYDwDg9gTgLgBAYwgOwM7wCbFQqBLMGPFVOAXjgG8AoOOAMwggC44AiAIwEMo3qBfatVCRYcGAE8wwOFhz5CxNOXFTgEerOy4CREkA

πŸ’» Code

export const descriptions = {
  foo: "bar"
}

export type descriptions = typeof descriptions

πŸ™ Actual behavior

Actual .d.ts output:

export declare const descriptions: typeof descriptions;
export type descriptions = typeof descriptions;

πŸ™‚ Expected behavior

Expected .d.ts output:

export declare const descriptions: {
    foo: string;
};
export type descriptions = typeof descriptions;

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label May 1, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.6.0 milestone May 1, 2024
@Andarist
Copy link
Contributor

Andarist commented May 1, 2024

Bisects to #57772

@ssalbdivad
Copy link
Author

@RyanCavanaugh Is this not worth patching into TS 5.5?

Given how easy this is to repro, I'd assume this would occur often in the wild.

Issues like this that are only exposed in build output are also particularly insidious because most library authors don't explicitly check their build output, and most consumers use skipLibCheck, which would result in the affected type silently resolving to any.

@patroza
Copy link

patroza commented May 2, 2024

This would be quite a disaster especially considering this only occurs in the .d.ts which for libraries are often generated just before publishing.

@mikearnaldi
Copy link

Following as Effect may be affected

@mikearnaldi
Copy link

Given that this was introduced before release wouldn't it be a better strategy to revert the commit that introduced the bug and defer that commit to 5.6? It feels a bit odd to introduce a bug, recognize that it is a bug and defer the fix till a further version. I would understand the choice if this didn't came up pre-release

@datner
Copy link

datner commented May 2, 2024

Hmm this matches a ton of common behavior, even the humble as const "enum" is affected.

export const Color = {
  Red: "Red",
  Green: "Green",
  Blue: "Blue"
} as const

export type Color = typeof Color
export type Colors = Color[keyof Color]

This being broked^
though this works fine:

export const Color = {
  Red: "Red",
  Green: "Green",
  Blue: "Blue"
} as const

export type Color = typeof Color[keyof typeof Color]

hmmmm

@RyanCavanaugh
Copy link
Member

Yeah, good points all around

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants