TypeScript
                                
                                 TypeScript copied to clipboard
                                
                                    TypeScript copied to clipboard
                            
                            
                            
                        typeof with identically named type and value causes invalid .d.ts output
🔎 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
Bisects to https://github.com/microsoft/TypeScript/pull/57772
@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.
This would be quite a disaster especially considering this only occurs in the .d.ts which for libraries are often generated just before publishing.
Following as Effect may be affected
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
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
Yeah, good points all around