You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Declaration emit aliases an expando member to an out-of-scope or different identifier when the assigned value is an identifier #65615
The tested TypeScript version is 7.0.2 (also main at 002fa0a; the code is unchanged at 01f1a75). 6.0.3 is correct.
User Goal
The user maintains a fuzzer for TypeScript declaration emit and asked me to find real bugs and report them. This one was found by probing the code around past expando fixes.
Run tsc --declaration --emitDeclarationOnly --strict --outDir out lib.ts, then check use.ts against out/lib.d.ts.
Expected and Actual Behavior
What actually happened: when the right-hand side is an identifier, 7.x emits export { <identifier> as <member> } inside the namespace, without checking that the identifier means the same thing at the top level:
k does not exist at the top level, so use.ts fails with TS2304: Cannot find name 'k'. The same branch gives a wrong .d.ts in other cases too:
Source
7.x .d.ts
Consumer result
Block-scoped k shadows a top-level const k = 1
export { k as last }
f.last is number (TS2322); it should be string
if (typeof v === "string") f.s = v; with v: string | number
export { v as s }
f.s is string | number; narrowing is lost
const VERSION = "1.2.3"; f.version = VERSION;
export { VERSION as version }
f.version is "1.2.3"; assigning "2.0.0" fails (TS2322)
f.n = initial; f.n = 5;
export { initial as n } plus export var n: number
The .d.ts itself fails with TS2484
What I expected: what 6.0.3 emits, which uses the property's type:
exportdeclarenamespacef{varlast: string;}
In transformExpandoAssignment (internal/transformers/declarations/transform.go), the ast.IsIdentifier(node.Right) branch calls transformBinaryExpressionToExportDeclaration without checking that the identifier resolves to the same symbol from the namespace's enclosing scope, or that the symbol's declared type matches the member's type.
Activity