Skip to content

Commit

Permalink
Infer type from assertion for export assignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirtitian committed Mar 5, 2024
1 parent 3833bf5 commit 5506934
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,8 @@ export function transformDeclarations(context: TransformationContext) {
errorNode: input,
});
errorFallbackNode = input;
const varDecl = factory.createVariableDeclaration(newId, /*exclamationToken*/ undefined, resolver.createTypeOfExpression(input.expression, input, declarationEmitNodeBuilderFlags, symbolTracker), /*initializer*/ undefined);
const type = ensureType(input);
const varDecl = factory.createVariableDeclaration(newId, /*exclamationToken*/ undefined, type, /*initializer*/ undefined);
errorFallbackNode = undefined;
const statement = factory.createVariableStatement(needsDeclare ? [factory.createModifier(SyntaxKind.DeclareKeyword)] : [], factory.createVariableDeclarationList([varDecl], NodeFlags.Const));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ export declare class C {
methodWithRequiredDefault(p: P, req: number): void;
constructor(ctorField?: P);
}
declare const _default: {
name: string;
};
declare const _default: P;
export default _default;
//// [assertToTypeLiteral.d.ts]
export declare let vLet: {} & {
Expand Down Expand Up @@ -277,7 +275,7 @@ export declare class C {
name: string;
});
}
declare const _default: {
declare const _default: {} & {
name: string;
};
export default _default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ export declare class C {
} | undefined, req: number): void;
constructor(ctorField?: P);
}
declare const _default: {
name: string;
};
declare const _default: P;
export default _default;
//// [assertToTypeLiteral.d.ts]
export declare let vLet: {} & {
Expand Down Expand Up @@ -281,7 +279,7 @@ export declare class C {
name: string;
});
}
declare const _default: {
declare const _default: {} & {
name: string;
};
export default _default;
Expand Down

0 comments on commit 5506934

Please sign in to comment.