diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b65eca1f8a3..8228f62fe0e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5459,7 +5459,7 @@ namespace ts { function serializeReturnTypeForSignature(context: NodeBuilderContext, type: Type, signature: Signature, includePrivateSymbol?: (s: Symbol) => void, bundled?: boolean) { if (type !== errorType && context.enclosingDeclaration) { const annotation = signature.declaration && getEffectiveReturnTypeNode(signature.declaration); - if (!!findAncestor(annotation, n => n === context.enclosingDeclaration) && annotation && getTypeFromTypeNode(annotation) === type) { + if (!!findAncestor(annotation, n => n === context.enclosingDeclaration) && annotation && instantiateType(getTypeFromTypeNode(annotation), signature.mapper) === type) { const result = serializeExistingTypeNode(context, annotation, includePrivateSymbol, bundled); if (result) { return result; @@ -6211,7 +6211,7 @@ namespace ts { ...!length(baseTypes) ? [] : [createHeritageClause(SyntaxKind.ExtendsKeyword, map(baseTypes, b => serializeBaseType(b, staticBaseType, localName)))], ...!length(implementsTypes) ? [] : [createHeritageClause(SyntaxKind.ImplementsKeyword, map(implementsTypes, b => serializeBaseType(b, staticBaseType, localName)))] ]; - const symbolProps = getPropertiesOfType(classType); + const symbolProps = getNonInterhitedProperties(classType, baseTypes, getPropertiesOfType(classType)); const publicSymbolProps = filter(symbolProps, s => { // `valueDeclaration` could be undefined if inherited from // a union/intersection base type, but inherited properties @@ -33482,6 +33482,26 @@ namespace ts { } } + function getNonInterhitedProperties(type: InterfaceType, baseTypes: BaseType[], properties: Symbol[]) { + if (!length(baseTypes)) { + return properties; + } + const seen = createUnderscoreEscapedMap(); + forEach(properties, p => { seen.set(p.escapedName, p); }); + + for (const base of baseTypes) { + const properties = getPropertiesOfType(getTypeWithThisArgument(base, type.thisType)); + for (const prop of properties) { + const existing = seen.get(prop.escapedName); + if (existing && !isPropertyIdenticalTo(existing, prop)) { + seen.delete(prop.escapedName); + } + } + } + + return arrayFrom(seen.values()); + } + function checkInheritedPropertiesAreIdentical(type: InterfaceType, typeNode: Node): boolean { const baseTypes = getBaseTypes(type); if (baseTypes.length < 2) { diff --git a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types index 142dedb2041..836c6ba044e 100644 --- a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types +++ b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types @@ -38,13 +38,13 @@ export const updateIfChanged = (t: T) => { >newU : U return Object.assign( ->Object.assign( >(key: K) => reduce>(u[key as keyof U] as Value, (v: Value) => { return update(Object.assign(Array.isArray(u) ? [] : {}, u, { [key]: v })); }), { map: (updater: (u: U) => U) => set(updater(u)), set }) : ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => any & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K][K][K]) => U[K][K][K][K][K][K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K][K]) => U[K][K][K][K][K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K]) => U[K][K][K][K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K]) => U[K][K][K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K]) => U[K][K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K]) => U[K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K]) => U[K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K]) => U[K][K][K][K]) => T; set: (newU: U[K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K]) => U[K][K][K]) => T; set: (newU: U[K][K][K]) => T; }) & { map: (updater: (u: U[K][K]) => U[K][K]) => T; set: (newU: U[K][K]) => T; }) & { map: (updater: (u: U[K]) => U[K]) => T; set: (newU: U[K]) => T; }) & { map: (updater: (u: U) => U) => T; set: (newU: U) => T; } +>Object.assign( >(key: K) => reduce>(u[key as keyof U] as Value, (v: Value) => { return update(Object.assign(Array.isArray(u) ? [] : {}, u, { [key]: v })); }), { map: (updater: (u: U) => U) => set(updater(u)), set }) : ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => any & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K]) => U) => T; set: (newU: U[K][K][K]) => T; }) & { map: (updater: (u: U[K][K]) => U) => T; set: (newU: U[K][K]) => T; }) & { map: (updater: (u: U[K]) => U) => T; set: (newU: U[K]) => T; }) & { map: (updater: (u: U) => U) => T; set: (newU: U) => T; } >Object.assign : { (target: T, source: U): T & U; (target: T, source1: U, source2: V): T & U & V; (target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; } >Object : ObjectConstructor >assign : { (target: T, source: U): T & U; (target: T, source1: U, source2: V): T & U & V; (target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; } >(key: K) => ->>(key: K) => reduce>(u[key as keyof U] as Value, (v: Value) => { return update(Object.assign(Array.isArray(u) ? [] : {}, u, { [key]: v })); }) : (key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => any & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K][K][K]) => U[K][K][K][K][K][K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K][K]) => U[K][K][K][K][K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K]) => U[K][K][K][K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K]) => U[K][K][K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K]) => U[K][K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K]) => U[K][K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K]) => U[K][K][K][K][K]) => T; set: (newU: U[K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K]) => U[K][K][K][K]) => T; set: (newU: U[K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K]) => U[K][K][K]) => T; set: (newU: U[K][K][K]) => T; }) & { map: (updater: (u: U[K][K]) => U[K][K]) => T; set: (newU: U[K][K]) => T; }) & { map: (updater: (u: U[K]) => U[K]) => T; set: (newU: U[K]) => T; } +>>(key: K) => reduce>(u[key as keyof U] as Value, (v: Value) => { return update(Object.assign(Array.isArray(u) ? [] : {}, u, { [key]: v })); }) : (key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => ((key: K) => any & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K][K]) => U) => T; set: (newU: U[K][K][K][K]) => T; }) & { map: (updater: (u: U[K][K][K]) => U) => T; set: (newU: U[K][K][K]) => T; }) & { map: (updater: (u: U[K][K]) => U) => T; set: (newU: U[K][K]) => T; }) & { map: (updater: (u: U[K]) => U) => T; set: (newU: U[K]) => T; } >key : K reduce>(u[key as keyof U] as Value, (v: Value) => { diff --git a/tests/baselines/reference/jsDeclarationsInterfaces.js b/tests/baselines/reference/jsDeclarationsInterfaces.js index 00e78c8286a..f7f68846d29 100644 --- a/tests/baselines/reference/jsDeclarationsInterfaces.js +++ b/tests/baselines/reference/jsDeclarationsInterfaces.js @@ -135,10 +135,10 @@ export interface B { export interface C { new (): string; new (x: T_1): U_1; - new (x: Q_4): T_1 & Q_4; + new (x: Q_6): T_1 & Q_6; (): number; (x: T_1): U_1; - (x: Q_3): T_1 & Q_3; + (x: Q_4): T_1 & Q_4; field: T_1 & U_1; optionalField?: T_1; readonly readonlyField: T_1 & U_1; diff --git a/tests/baselines/reference/jsDeclarationsThisTypes.js b/tests/baselines/reference/jsDeclarationsThisTypes.js new file mode 100644 index 00000000000..65858ab41dc --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsThisTypes.js @@ -0,0 +1,59 @@ +//// [index.js] +export class A { + /** @returns {this} */ + method() { + return this; + } +} +export default class Base extends A { + // This method is required to reproduce #35932 + verify() { } +} + +//// [index.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +exports.A = void 0; +var A = /** @class */ (function () { + function A() { + } + /** @returns {this} */ + A.prototype.method = function () { + return this; + }; + return A; +}()); +exports.A = A; +var Base = /** @class */ (function (_super) { + __extends(Base, _super); + function Base() { + return _super !== null && _super.apply(this, arguments) || this; + } + // This method is required to reproduce #35932 + Base.prototype.verify = function () { }; + return Base; +}(A)); +exports["default"] = Base; + + +//// [index.d.ts] +export class A { + /** @returns {this} */ + method(): this; +} +export default class Base extends A { + verify(): void; +} diff --git a/tests/baselines/reference/jsDeclarationsThisTypes.symbols b/tests/baselines/reference/jsDeclarationsThisTypes.symbols new file mode 100644 index 00000000000..931bdd24a97 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsThisTypes.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +export class A { +>A : Symbol(A, Decl(index.js, 0, 0)) + + /** @returns {this} */ + method() { +>method : Symbol(A.method, Decl(index.js, 0, 16)) + + return this; +>this : Symbol(A, Decl(index.js, 0, 0)) + } +} +export default class Base extends A { +>Base : Symbol(Base, Decl(index.js, 5, 1)) +>A : Symbol(A, Decl(index.js, 0, 0)) + + // This method is required to reproduce #35932 + verify() { } +>verify : Symbol(Base.verify, Decl(index.js, 6, 37)) +} diff --git a/tests/baselines/reference/jsDeclarationsThisTypes.types b/tests/baselines/reference/jsDeclarationsThisTypes.types new file mode 100644 index 00000000000..801f1792656 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsThisTypes.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +export class A { +>A : A + + /** @returns {this} */ + method() { +>method : () => this + + return this; +>this : this + } +} +export default class Base extends A { +>Base : Base +>A : A + + // This method is required to reproduce #35932 + verify() { } +>verify : () => void +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsThisTypes.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsThisTypes.ts new file mode 100644 index 00000000000..bc2eae7dac6 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsThisTypes.ts @@ -0,0 +1,17 @@ +// @allowJs: true +// @checkJs: true +// @outDir: /out +// @lib: es6 +// @declaration: true +// @filename: index.js + +export class A { + /** @returns {this} */ + method() { + return this; + } +} +export default class Base extends A { + // This method is required to reproduce #35932 + verify() { } +} \ No newline at end of file