-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Fixed declaration emit for undefined properties inferred from functions in other array elements #53938
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
Fixed declaration emit for undefined properties inferred from functions in other array elements #53938
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7154,35 +7154,36 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
| const methodDeclaration = signatureToSignatureDeclarationHelper(signature, SyntaxKind.MethodSignature, context, { name: propertyName, questionToken: optionalToken }) as MethodSignature; | ||
| typeElements.push(preserveCommentsOn(methodDeclaration)); | ||
| } | ||
| if (signatures.length || !optionalToken) { | ||
| return; | ||
| } | ||
|
Comment on lines
+7157
to
+7159
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the fix, the rest is just dedented because now we fallthrough to the rest of the logic in this case
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To that end, handy better diff link: https://github.com/microsoft/TypeScript/pull/53938/files?w=1 |
||
| } | ||
| let propertyTypeNode: TypeNode; | ||
| if (shouldUsePlaceholderForProperty(propertySymbol, context)) { | ||
| propertyTypeNode = createElidedInformationPlaceholder(context); | ||
| } | ||
| else { | ||
| let propertyTypeNode: TypeNode; | ||
| if (shouldUsePlaceholderForProperty(propertySymbol, context)) { | ||
| propertyTypeNode = createElidedInformationPlaceholder(context); | ||
| if (propertyIsReverseMapped) { | ||
| context.reverseMappedStack ||= []; | ||
| context.reverseMappedStack.push(propertySymbol as ReverseMappedSymbol); | ||
| } | ||
| else { | ||
| if (propertyIsReverseMapped) { | ||
| context.reverseMappedStack ||= []; | ||
| context.reverseMappedStack.push(propertySymbol as ReverseMappedSymbol); | ||
| } | ||
| propertyTypeNode = propertyType ? serializeTypeForDeclaration(context, propertyType, propertySymbol, saveEnclosingDeclaration) : factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); | ||
| if (propertyIsReverseMapped) { | ||
| context.reverseMappedStack!.pop(); | ||
| } | ||
| propertyTypeNode = propertyType ? serializeTypeForDeclaration(context, propertyType, propertySymbol, saveEnclosingDeclaration) : factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); | ||
| if (propertyIsReverseMapped) { | ||
| context.reverseMappedStack!.pop(); | ||
| } | ||
| } | ||
|
|
||
| const modifiers = isReadonlySymbol(propertySymbol) ? [factory.createToken(SyntaxKind.ReadonlyKeyword)] : undefined; | ||
| if (modifiers) { | ||
| context.approximateLength += 9; | ||
| } | ||
| const propertySignature = factory.createPropertySignature( | ||
| modifiers, | ||
| propertyName, | ||
| optionalToken, | ||
| propertyTypeNode); | ||
|
|
||
| typeElements.push(preserveCommentsOn(propertySignature)); | ||
| const modifiers = isReadonlySymbol(propertySymbol) ? [factory.createToken(SyntaxKind.ReadonlyKeyword)] : undefined; | ||
| if (modifiers) { | ||
| context.approximateLength += 9; | ||
| } | ||
| const propertySignature = factory.createPropertySignature( | ||
| modifiers, | ||
| propertyName, | ||
| optionalToken, | ||
| propertyTypeNode); | ||
|
|
||
| typeElements.push(preserveCommentsOn(propertySignature)); | ||
|
|
||
| function preserveCommentsOn<T extends Node>(node: T) { | ||
| if (some(propertySymbol.declarations, d => d.kind === SyntaxKind.JSDocPropertyTag)) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //// [declarationEmitInferredUndefinedPropFromFunctionInArray.ts] | ||
| // repro from https://github.com/microsoft/TypeScript/issues/53914 | ||
|
|
||
| export let b = [{ foo: 0, m() {} }, { bar: 1 }]; | ||
|
|
||
| //// [declarationEmitInferredUndefinedPropFromFunctionInArray.js] | ||
| "use strict"; | ||
| // repro from https://github.com/microsoft/TypeScript/issues/53914 | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.b = void 0; | ||
| exports.b = [{ foo: 0, m: function () { } }, { bar: 1 }]; | ||
|
|
||
|
|
||
| //// [declarationEmitInferredUndefinedPropFromFunctionInArray.d.ts] | ||
| export declare let b: ({ | ||
| foo: number; | ||
| m(): void; | ||
| bar?: undefined; | ||
| } | { | ||
| bar: number; | ||
| foo?: undefined; | ||
| m?: undefined; | ||
| })[]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| === tests/cases/compiler/declarationEmitInferredUndefinedPropFromFunctionInArray.ts === | ||
| // repro from https://github.com/microsoft/TypeScript/issues/53914 | ||
|
|
||
| export let b = [{ foo: 0, m() {} }, { bar: 1 }]; | ||
| >b : Symbol(b, Decl(declarationEmitInferredUndefinedPropFromFunctionInArray.ts, 2, 10)) | ||
| >foo : Symbol(foo, Decl(declarationEmitInferredUndefinedPropFromFunctionInArray.ts, 2, 17)) | ||
| >m : Symbol(m, Decl(declarationEmitInferredUndefinedPropFromFunctionInArray.ts, 2, 25)) | ||
| >bar : Symbol(bar, Decl(declarationEmitInferredUndefinedPropFromFunctionInArray.ts, 2, 37)) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| === tests/cases/compiler/declarationEmitInferredUndefinedPropFromFunctionInArray.ts === | ||
| // repro from https://github.com/microsoft/TypeScript/issues/53914 | ||
|
|
||
| export let b = [{ foo: 0, m() {} }, { bar: 1 }]; | ||
| >b : ({ foo: number; m(): void; bar?: undefined; } | { bar: number; foo?: undefined; m?: undefined; })[] | ||
| >[{ foo: 0, m() {} }, { bar: 1 }] : ({ foo: number; m(): void; } | { bar: number; })[] | ||
| >{ foo: 0, m() {} } : { foo: number; m(): void; } | ||
| >foo : number | ||
| >0 : 0 | ||
| >m : () => void | ||
| >{ bar: 1 } : { bar: number; } | ||
| >bar : number | ||
| >1 : 1 | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // @declaration: true | ||
|
|
||
| // repro from https://github.com/microsoft/TypeScript/issues/53914 | ||
|
|
||
| export let b = [{ foo: 0, m() {} }, { bar: 1 }]; |
Uh oh!
There was an error while loading. Please reload this page.