From 257812cec571de68729e75b04b31e42570c2aed3 Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Mon, 7 Jan 2019 13:04:54 -0800 Subject: [PATCH 1/8] fix type derived from prototype assignment --- src/compiler/checker.ts | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3377ae96b0ded..e8c2b5d87d426 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8611,8 +8611,11 @@ namespace ts { if (symbol.flags & SymbolFlags.Function && isJSDocTypeReference(node) && - (symbol.members || getJSDocClassTag(symbol.valueDeclaration))) { - return getInferredClassType(symbol); + (symbol.members || getJSDocClassTag(symbol.valueDeclaration))) { // todo change condition to isJsConstructor + const resolved = resolveStructuredTypeMembers(getTypeOfSymbol(symbol)); + if (resolved.callSignatures.length === 1) { + return getReturnTypeOfSignature(resolved.callSignatures[0]); + } } } @@ -16632,7 +16635,7 @@ namespace ts { else if (isInJS && (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) && getJSDocClassTag(container)) { - const classType = getJSClassType(container.symbol); + const classType = getJSClassType(getMergedSymbol(container.symbol)); if (classType) { return getFlowTypeOfReference(node, classType); } @@ -20770,7 +20773,7 @@ namespace ts { // If the symbol of the node has members, treat it like a constructor. const symbol = getSymbolOfNode(func); - return !!symbol && symbol.members !== undefined; + return !!symbol && (symbol.members !== undefined || symbol.exports !== undefined && symbol.exports.get("prototype" as __String) !== undefined); } return false; } @@ -20789,10 +20792,6 @@ namespace ts { inferred = getInferredClassType(symbol); } const assigned = getAssignedClassType(symbol); - const valueType = getTypeOfSymbol(symbol); - if (valueType.symbol && !isInferredClassType(valueType) && isJSConstructor(valueType.symbol.valueDeclaration)) { - inferred = getInferredClassType(valueType.symbol); - } return assigned && inferred ? getIntersectionType([inferred, assigned]) : assigned || inferred; @@ -20859,21 +20858,10 @@ namespace ts { declaration.kind !== SyntaxKind.Constructor && declaration.kind !== SyntaxKind.ConstructSignature && declaration.kind !== SyntaxKind.ConstructorType && - !isJSDocConstructSignature(declaration)) { + !isJSDocConstructSignature(declaration) && + !isJSConstructor(declaration)) { - // When resolved signature is a call signature (and not a construct signature) the result type is any, unless - // the declaring function had members created through 'x.prototype.y = expr' or 'this.y = expr' psuedodeclarations - // in a JS file - // Note:JS inferred classes might come from a variable declaration instead of a function declaration. - // In this case, using getResolvedSymbol directly is required to avoid losing the members from the declaration. - let funcSymbol = checkExpression(node.expression).symbol; - if (!funcSymbol && node.expression.kind === SyntaxKind.Identifier) { - funcSymbol = getResolvedSymbol(node.expression as Identifier); - } - const type = funcSymbol && getJSClassType(funcSymbol); - if (type) { - return signature.target ? instantiateType(type, signature.mapper) : type; - } + // When resolved signature is a call signature (and not a construct signature) the result type is any if (noImplicitAny) { error(node, Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); } From aba1f91dc04a50c88e5a2bc3225517543130857f Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Mon, 7 Jan 2019 13:17:23 -0800 Subject: [PATCH 2/8] accept new baselines --- .../classCanExtendConstructorFunction.types | 6 +++--- .../reference/jsContainerMergeJsContainer.types | 12 ++++++------ .../reference/typeFromPropertyAssignment14.types | 16 ++++++++-------- .../reference/typeFromPropertyAssignment16.types | 16 ++++++++-------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/baselines/reference/classCanExtendConstructorFunction.types b/tests/baselines/reference/classCanExtendConstructorFunction.types index f42366976fc39..c9ac9c76ebf37 100644 --- a/tests/baselines/reference/classCanExtendConstructorFunction.types +++ b/tests/baselines/reference/classCanExtendConstructorFunction.types @@ -269,8 +269,8 @@ soup.flavour >flavour : number var chowder = new Chowder({ claim: "ignorant" }); ->chowder : any ->new Chowder({ claim: "ignorant" }) : any +>chowder : Chowder +>new Chowder({ claim: "ignorant" }) : Chowder >Chowder : typeof Chowder >{ claim: "ignorant" } : { claim: "ignorant"; } >claim : "ignorant" @@ -279,7 +279,7 @@ var chowder = new Chowder({ claim: "ignorant" }); chowder.flavour.claim >chowder.flavour.claim : any >chowder.flavour : any ->chowder : any +>chowder : Chowder >flavour : any >claim : any diff --git a/tests/baselines/reference/jsContainerMergeJsContainer.types b/tests/baselines/reference/jsContainerMergeJsContainer.types index 73e61aded0df9..56cb598269dbc 100644 --- a/tests/baselines/reference/jsContainerMergeJsContainer.types +++ b/tests/baselines/reference/jsContainerMergeJsContainer.types @@ -5,19 +5,19 @@ const a = {}; >{} : {} a.d = function() {}; ->a.d = function() {} : { (): void; prototype: {}; } ->a.d : { (): void; prototype: {}; } +>a.d = function() {} : typeof d +>a.d : typeof d >a : typeof a ->d : { (): void; prototype: {}; } ->function() {} : { (): void; prototype: {}; } +>d : typeof d +>function() {} : typeof d === tests/cases/conformance/salsa/b.js === a.d.prototype = {}; >a.d.prototype = {} : {} >a.d.prototype : {} ->a.d : { (): void; prototype: {}; } +>a.d : typeof d >a : typeof a ->d : { (): void; prototype: {}; } +>d : typeof d >prototype : {} >{} : {} diff --git a/tests/baselines/reference/typeFromPropertyAssignment14.types b/tests/baselines/reference/typeFromPropertyAssignment14.types index bc1b2a69be9b0..bb8169db35949 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment14.types +++ b/tests/baselines/reference/typeFromPropertyAssignment14.types @@ -5,18 +5,18 @@ var Outer = {}; === tests/cases/conformance/salsa/work.js === Outer.Inner = function () {} ->Outer.Inner = function () {} : { (): void; prototype: { x: number; m(): void; }; } ->Outer.Inner : { (): void; prototype: { x: number; m(): void; }; } +>Outer.Inner = function () {} : typeof Inner +>Outer.Inner : typeof Inner >Outer : typeof Outer ->Inner : { (): void; prototype: { x: number; m(): void; }; } ->function () {} : { (): void; prototype: { x: number; m(): void; }; } +>Inner : typeof Inner +>function () {} : typeof Inner Outer.Inner.prototype = { >Outer.Inner.prototype = { x: 1, m() { }} : { x: number; m(): void; } >Outer.Inner.prototype : { x: number; m(): void; } ->Outer.Inner : { (): void; prototype: { x: number; m(): void; }; } +>Outer.Inner : typeof Inner >Outer : typeof Outer ->Inner : { (): void; prototype: { x: number; m(): void; }; } +>Inner : typeof Inner >prototype : { x: number; m(): void; } >{ x: 1, m() { }} : { x: number; m(): void; } @@ -47,9 +47,9 @@ inner.m() var inno = new Outer.Inner() >inno : { x: number; m(): void; } >new Outer.Inner() : { x: number; m(): void; } ->Outer.Inner : { (): void; prototype: { x: number; m(): void; }; } +>Outer.Inner : typeof Inner >Outer : typeof Outer ->Inner : { (): void; prototype: { x: number; m(): void; }; } +>Inner : typeof Inner inno.x >inno.x : number diff --git a/tests/baselines/reference/typeFromPropertyAssignment16.types b/tests/baselines/reference/typeFromPropertyAssignment16.types index f2cb476e5fa30..1d94d096ea02c 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment16.types +++ b/tests/baselines/reference/typeFromPropertyAssignment16.types @@ -4,18 +4,18 @@ var Outer = {}; >{} : {} Outer.Inner = function () {} ->Outer.Inner = function () {} : { (): void; prototype: { x: number; m(): void; }; } ->Outer.Inner : { (): void; prototype: { x: number; m(): void; }; } +>Outer.Inner = function () {} : typeof Inner +>Outer.Inner : typeof Inner >Outer : typeof Outer ->Inner : { (): void; prototype: { x: number; m(): void; }; } ->function () {} : { (): void; prototype: { x: number; m(): void; }; } +>Inner : typeof Inner +>function () {} : typeof Inner Outer.Inner.prototype = { >Outer.Inner.prototype = { x: 1, m() { }} : { x: number; m(): void; } >Outer.Inner.prototype : { x: number; m(): void; } ->Outer.Inner : { (): void; prototype: { x: number; m(): void; }; } +>Outer.Inner : typeof Inner >Outer : typeof Outer ->Inner : { (): void; prototype: { x: number; m(): void; }; } +>Inner : typeof Inner >prototype : { x: number; m(): void; } >{ x: 1, m() { }} : { x: number; m(): void; } @@ -45,9 +45,9 @@ inner.m() var inno = new Outer.Inner() >inno : { x: number; m(): void; } >new Outer.Inner() : { x: number; m(): void; } ->Outer.Inner : { (): void; prototype: { x: number; m(): void; }; } +>Outer.Inner : typeof Inner >Outer : typeof Outer ->Inner : { (): void; prototype: { x: number; m(): void; }; } +>Inner : typeof Inner inno.x >inno.x : number From 986aaa7e4d9ccac85269ffa5d2e9119a307a5e6e Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Mon, 7 Jan 2019 16:23:17 -0800 Subject: [PATCH 3/8] remove direct intersection with object literal assigned to prototype --- src/compiler/checker.ts | 9 +++------ ...eTagCircularReferenceOnConstructorFunction.errors.txt | 5 +---- .../user/TypeScript-Node-Starter/TypeScript-Node-Starter | 2 +- .../user/TypeScript-Vue-Starter/TypeScript-Vue-Starter | 2 +- tests/cases/user/axios-src/axios-src | 2 +- tests/cases/user/create-react-app/create-react-app | 2 +- tests/cases/user/prettier/prettier | 2 +- tests/cases/user/puppeteer/puppeteer | 2 +- tests/cases/user/webpack/webpack | 2 +- 9 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f77b47452a6b3..f28aa0b435184 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8690,7 +8690,6 @@ namespace ts { if (!pushTypeResolution(symbol, TypeSystemPropertyName.JSDocTypeReference)) { return errorType; } - const assignedType = getAssignedClassType(symbol); const valueType = getTypeOfSymbol(symbol); const referenceType = valueType.symbol && valueType.symbol !== symbol && !isInferredClassType(valueType) && getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments); if (!popTypeResolution()) { @@ -8698,10 +8697,8 @@ namespace ts { error(node, Diagnostics.JSDoc_type_0_circularly_references_itself, symbolToString(symbol)); return errorType; } - if (referenceType || assignedType) { - // TODO: GH#18217 (should the `|| assignedType` be at a lower precedence?) - const type = (referenceType && assignedType ? getIntersectionType([assignedType, referenceType]) : referenceType || assignedType)!; - return getSymbolLinks(symbol).resolvedJSDocType = type; + if (referenceType) { + return getSymbolLinks(symbol).resolvedJSDocType = referenceType; } } @@ -8722,7 +8719,7 @@ namespace ts { if (symbol.flags & SymbolFlags.Function && isJSDocTypeReference(node) && - (symbol.members || getJSDocClassTag(symbol.valueDeclaration))) { // todo change condition to isJsConstructor + isJSConstructor(symbol.valueDeclaration)) { const resolved = resolveStructuredTypeMembers(getTypeOfSymbol(symbol)); if (resolved.callSignatures.length === 1) { return getReturnTypeOfSignature(resolved.callSignatures[0]); diff --git a/tests/baselines/reference/typeTagCircularReferenceOnConstructorFunction.errors.txt b/tests/baselines/reference/typeTagCircularReferenceOnConstructorFunction.errors.txt index 2469e647685eb..d98cb9297dc37 100644 --- a/tests/baselines/reference/typeTagCircularReferenceOnConstructorFunction.errors.txt +++ b/tests/baselines/reference/typeTagCircularReferenceOnConstructorFunction.errors.txt @@ -1,14 +1,11 @@ tests/cases/conformance/jsdoc/bug27346.js(2,4): error TS8030: The type of a function declaration must match the function's signature. -tests/cases/conformance/jsdoc/bug27346.js(2,11): error TS2587: JSDoc type 'MyClass' circularly references itself. -==== tests/cases/conformance/jsdoc/bug27346.js (2 errors) ==== +==== tests/cases/conformance/jsdoc/bug27346.js (1 errors) ==== /** * @type {MyClass} ~~~~~~~~~~~~~~~ !!! error TS8030: The type of a function declaration must match the function's signature. - ~~~~~~~ -!!! error TS2587: JSDoc type 'MyClass' circularly references itself. */ function MyClass() { } MyClass.prototype = {}; diff --git a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter index 40bdb4eadabc9..4779cb7e182cf 160000 --- a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter +++ b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter @@ -1 +1 @@ -Subproject commit 40bdb4eadabc9fbed7d83e3f26817a931c0763b6 +Subproject commit 4779cb7e182cf41d5c62289bb80d2850e0265b71 diff --git a/tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter b/tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter index 713c6986f043f..c243b11a6f827 160000 --- a/tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter +++ b/tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter @@ -1 +1 @@ -Subproject commit 713c6986f043f2c31976b8bc2c03aa0a2b05590b +Subproject commit c243b11a6f827e780a5163999bc472c95ff5a0e0 diff --git a/tests/cases/user/axios-src/axios-src b/tests/cases/user/axios-src/axios-src index 0b3db5d87a60a..75c8b3f146aaa 160000 --- a/tests/cases/user/axios-src/axios-src +++ b/tests/cases/user/axios-src/axios-src @@ -1 +1 @@ -Subproject commit 0b3db5d87a60a1ad8b0dce9669dbc10483ec33da +Subproject commit 75c8b3f146aaa8a71f7dca0263686fb1799f8f31 diff --git a/tests/cases/user/create-react-app/create-react-app b/tests/cases/user/create-react-app/create-react-app index 1d4fdc2dd4950..d671b8fb0430d 160000 --- a/tests/cases/user/create-react-app/create-react-app +++ b/tests/cases/user/create-react-app/create-react-app @@ -1 +1 @@ -Subproject commit 1d4fdc2dd4950011beacf1883900bf5d8da7079e +Subproject commit d671b8fb0430d11ebc6f399274bd5f2cfbb1de65 diff --git a/tests/cases/user/prettier/prettier b/tests/cases/user/prettier/prettier index 67f1c4877ee10..7238ceffab786 160000 --- a/tests/cases/user/prettier/prettier +++ b/tests/cases/user/prettier/prettier @@ -1 +1 @@ -Subproject commit 67f1c4877ee1090b66d468a847caccca411a6f82 +Subproject commit 7238ceffab786511a1162ab6023f2ff177fcddcf diff --git a/tests/cases/user/puppeteer/puppeteer b/tests/cases/user/puppeteer/puppeteer index 98bb2615adb68..9800b2c3c2d31 160000 --- a/tests/cases/user/puppeteer/puppeteer +++ b/tests/cases/user/puppeteer/puppeteer @@ -1 +1 @@ -Subproject commit 98bb2615adb6815c91efcc59593b49e2ec8c3935 +Subproject commit 9800b2c3c2d31379badb9d4dab1cc8fc95aee48a diff --git a/tests/cases/user/webpack/webpack b/tests/cases/user/webpack/webpack index 10282ea20648b..8be048550f87e 160000 --- a/tests/cases/user/webpack/webpack +++ b/tests/cases/user/webpack/webpack @@ -1 +1 @@ -Subproject commit 10282ea20648b465caec6448849f24fc34e1ba3e +Subproject commit 8be048550f87eac9f118b05c269caa59443c87b4 From e1f786baaceabbfaf2653f94f5acaa8146f39418 Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Mon, 7 Jan 2019 16:45:41 -0800 Subject: [PATCH 4/8] add tests --- .../typeFromPrototypeAssignment3.errors.txt | 26 +++++++++ .../typeFromPrototypeAssignment3.symbols | 40 ++++++++++++++ .../typeFromPrototypeAssignment3.types | 53 +++++++++++++++++++ .../salsa/typeFromPrototypeAssignment3.ts | 23 ++++++++ 4 files changed, 142 insertions(+) create mode 100644 tests/baselines/reference/typeFromPrototypeAssignment3.errors.txt create mode 100644 tests/baselines/reference/typeFromPrototypeAssignment3.symbols create mode 100644 tests/baselines/reference/typeFromPrototypeAssignment3.types create mode 100644 tests/cases/conformance/salsa/typeFromPrototypeAssignment3.ts diff --git a/tests/baselines/reference/typeFromPrototypeAssignment3.errors.txt b/tests/baselines/reference/typeFromPrototypeAssignment3.errors.txt new file mode 100644 index 0000000000000..579c3efac7265 --- /dev/null +++ b/tests/baselines/reference/typeFromPrototypeAssignment3.errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/salsa/bug26885.js(2,5): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. +tests/cases/conformance/salsa/bug26885.js(11,16): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. + + +==== tests/cases/conformance/salsa/bug26885.js (2 errors) ==== + function Multimap3() { + this._map = {}; + ~~~~ +!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. + }; + + Multimap3.prototype = { + /** + * @param {string} key + * @returns {number} the value ok + */ + get(key) { + return this._map[key + '']; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. + } + } + + /** @type {Multimap3} */ + const map = new Multimap3(); + const n = map.get('hi') \ No newline at end of file diff --git a/tests/baselines/reference/typeFromPrototypeAssignment3.symbols b/tests/baselines/reference/typeFromPrototypeAssignment3.symbols new file mode 100644 index 0000000000000..65b72e9441b7c --- /dev/null +++ b/tests/baselines/reference/typeFromPrototypeAssignment3.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/salsa/bug26885.js === +function Multimap3() { +>Multimap3 : Symbol(Multimap3, Decl(bug26885.js, 0, 0), Decl(bug26885.js, 2, 2)) + + this._map = {}; +>_map : Symbol(Multimap3._map, Decl(bug26885.js, 0, 22)) + +}; + +Multimap3.prototype = { +>Multimap3.prototype : Symbol(Multimap3.prototype, Decl(bug26885.js, 2, 2)) +>Multimap3 : Symbol(Multimap3, Decl(bug26885.js, 0, 0), Decl(bug26885.js, 2, 2)) +>prototype : Symbol(Multimap3.prototype, Decl(bug26885.js, 2, 2)) + + /** + * @param {string} key + * @returns {number} the value ok + */ + get(key) { +>get : Symbol(get, Decl(bug26885.js, 4, 23)) +>key : Symbol(key, Decl(bug26885.js, 9, 8)) + + return this._map[key + '']; +>this._map : Symbol(Multimap3._map, Decl(bug26885.js, 0, 22)) +>_map : Symbol(Multimap3._map, Decl(bug26885.js, 0, 22)) +>key : Symbol(key, Decl(bug26885.js, 9, 8)) + } +} + +/** @type {Multimap3} */ +const map = new Multimap3(); +>map : Symbol(map, Decl(bug26885.js, 15, 5)) +>Multimap3 : Symbol(Multimap3, Decl(bug26885.js, 0, 0), Decl(bug26885.js, 2, 2)) + +const n = map.get('hi') +>n : Symbol(n, Decl(bug26885.js, 16, 5)) +>map.get : Symbol(get, Decl(bug26885.js, 4, 23)) +>map : Symbol(map, Decl(bug26885.js, 15, 5)) +>get : Symbol(get, Decl(bug26885.js, 4, 23)) + diff --git a/tests/baselines/reference/typeFromPrototypeAssignment3.types b/tests/baselines/reference/typeFromPrototypeAssignment3.types new file mode 100644 index 0000000000000..82fef59c42afc --- /dev/null +++ b/tests/baselines/reference/typeFromPrototypeAssignment3.types @@ -0,0 +1,53 @@ +=== tests/cases/conformance/salsa/bug26885.js === +function Multimap3() { +>Multimap3 : typeof Multimap3 + + this._map = {}; +>this._map = {} : {} +>this._map : any +>this : any +>_map : any +>{} : {} + +}; + +Multimap3.prototype = { +>Multimap3.prototype = { /** * @param {string} key * @returns {number} the value ok */ get(key) { return this._map[key + '']; }} : { get(key: string): number; } +>Multimap3.prototype : { get(key: string): number; } +>Multimap3 : typeof Multimap3 +>prototype : { get(key: string): number; } +>{ /** * @param {string} key * @returns {number} the value ok */ get(key) { return this._map[key + '']; }} : { get(key: string): number; } + + /** + * @param {string} key + * @returns {number} the value ok + */ + get(key) { +>get : (key: string) => number +>key : string + + return this._map[key + '']; +>this._map[key + ''] : any +>this._map : {} +>this : Multimap3 & { get(key: string): number; } +>_map : {} +>key + '' : string +>key : string +>'' : "" + } +} + +/** @type {Multimap3} */ +const map = new Multimap3(); +>map : Multimap3 & { get(key: string): number; } +>new Multimap3() : Multimap3 & { get(key: string): number; } +>Multimap3 : typeof Multimap3 + +const n = map.get('hi') +>n : number +>map.get('hi') : number +>map.get : (key: string) => number +>map : Multimap3 & { get(key: string): number; } +>get : (key: string) => number +>'hi' : "hi" + diff --git a/tests/cases/conformance/salsa/typeFromPrototypeAssignment3.ts b/tests/cases/conformance/salsa/typeFromPrototypeAssignment3.ts new file mode 100644 index 0000000000000..00475db6cc1b5 --- /dev/null +++ b/tests/cases/conformance/salsa/typeFromPrototypeAssignment3.ts @@ -0,0 +1,23 @@ +// @noEmit: true +// @allowJs: true +// @checkJs: true +// @Filename: bug26885.js +// @strict: true + +function Multimap3() { + this._map = {}; +}; + +Multimap3.prototype = { + /** + * @param {string} key + * @returns {number} the value ok + */ + get(key) { + return this._map[key + '']; + } +} + +/** @type {Multimap3} */ +const map = new Multimap3(); +const n = map.get('hi') \ No newline at end of file From ecb0becaec8439ed5b45e9be9d4f9ba4ddac4336 Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Tue, 8 Jan 2019 11:03:34 -0800 Subject: [PATCH 5/8] change webpack submodule commit --- tests/cases/user/webpack/webpack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/user/webpack/webpack b/tests/cases/user/webpack/webpack index 8be048550f87e..10282ea20648b 160000 --- a/tests/cases/user/webpack/webpack +++ b/tests/cases/user/webpack/webpack @@ -1 +1 @@ -Subproject commit 8be048550f87eac9f118b05c269caa59443c87b4 +Subproject commit 10282ea20648b465caec6448849f24fc34e1ba3e From 6cec484ee79d9f1aad95fd358776ef8e78662e63 Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Tue, 8 Jan 2019 11:11:01 -0800 Subject: [PATCH 6/8] fix submodule commits --- .../cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter | 2 +- tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter | 2 +- tests/cases/user/axios-src/axios-src | 2 +- tests/cases/user/create-react-app/create-react-app | 2 +- tests/cases/user/prettier/prettier | 2 +- tests/cases/user/puppeteer/puppeteer | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter index 4779cb7e182cf..40bdb4eadabc9 160000 --- a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter +++ b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter @@ -1 +1 @@ -Subproject commit 4779cb7e182cf41d5c62289bb80d2850e0265b71 +Subproject commit 40bdb4eadabc9fbed7d83e3f26817a931c0763b6 diff --git a/tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter b/tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter index c243b11a6f827..713c6986f043f 160000 --- a/tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter +++ b/tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter @@ -1 +1 @@ -Subproject commit c243b11a6f827e780a5163999bc472c95ff5a0e0 +Subproject commit 713c6986f043f2c31976b8bc2c03aa0a2b05590b diff --git a/tests/cases/user/axios-src/axios-src b/tests/cases/user/axios-src/axios-src index 75c8b3f146aaa..0b3db5d87a60a 160000 --- a/tests/cases/user/axios-src/axios-src +++ b/tests/cases/user/axios-src/axios-src @@ -1 +1 @@ -Subproject commit 75c8b3f146aaa8a71f7dca0263686fb1799f8f31 +Subproject commit 0b3db5d87a60a1ad8b0dce9669dbc10483ec33da diff --git a/tests/cases/user/create-react-app/create-react-app b/tests/cases/user/create-react-app/create-react-app index d671b8fb0430d..1d4fdc2dd4950 160000 --- a/tests/cases/user/create-react-app/create-react-app +++ b/tests/cases/user/create-react-app/create-react-app @@ -1 +1 @@ -Subproject commit d671b8fb0430d11ebc6f399274bd5f2cfbb1de65 +Subproject commit 1d4fdc2dd4950011beacf1883900bf5d8da7079e diff --git a/tests/cases/user/prettier/prettier b/tests/cases/user/prettier/prettier index 7238ceffab786..67f1c4877ee10 160000 --- a/tests/cases/user/prettier/prettier +++ b/tests/cases/user/prettier/prettier @@ -1 +1 @@ -Subproject commit 7238ceffab786511a1162ab6023f2ff177fcddcf +Subproject commit 67f1c4877ee1090b66d468a847caccca411a6f82 diff --git a/tests/cases/user/puppeteer/puppeteer b/tests/cases/user/puppeteer/puppeteer index 9800b2c3c2d31..98bb2615adb68 160000 --- a/tests/cases/user/puppeteer/puppeteer +++ b/tests/cases/user/puppeteer/puppeteer @@ -1 +1 @@ -Subproject commit 9800b2c3c2d31379badb9d4dab1cc8fc95aee48a +Subproject commit 98bb2615adb6815c91efcc59593b49e2ec8c3935 From 3c137c9d849b16857bd4ff7f296f2ec52ac7b16f Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Fri, 18 Jan 2019 11:38:15 -0800 Subject: [PATCH 7/8] comment and simplify getJSDocTypeReference --- src/compiler/checker.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f28aa0b435184..63561b42adfd8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8690,15 +8690,23 @@ namespace ts { if (!pushTypeResolution(symbol, TypeSystemPropertyName.JSDocTypeReference)) { return errorType; } - const valueType = getTypeOfSymbol(symbol); - const referenceType = valueType.symbol && valueType.symbol !== symbol && !isInferredClassType(valueType) && getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments); + const staticType = getTypeOfSymbol(symbol); + + // In the case of an assignment of a function expression (binary expressions, variable declarations, etc.), we will get the + // correct instance type for the symbol on the LHS by finding the type for RHS. For example if we want to get the type of the symbol `foo`: + // var foo = function() {} + // We will find the static type of the assigned anonymous function. + const instanceType = + staticType.symbol && + staticType.symbol !== symbol && // Make sure this is an assignment like expression by checking that symbol -> type -> symbol doesn't roundtrips. + getTypeReferenceTypeWorker(node, staticType.symbol, typeArguments); // Get the instance type of the RHS symbol. if (!popTypeResolution()) { getSymbolLinks(symbol).resolvedJSDocType = errorType; error(node, Diagnostics.JSDoc_type_0_circularly_references_itself, symbolToString(symbol)); return errorType; } - if (referenceType) { - return getSymbolLinks(symbol).resolvedJSDocType = referenceType; + if (instanceType) { + return getSymbolLinks(symbol).resolvedJSDocType = instanceType; } } @@ -20951,12 +20959,6 @@ namespace ts { return links.inferredClassType; } - function isInferredClassType(type: Type) { - return type.symbol - && getObjectFlags(type) & ObjectFlags.Anonymous - && getSymbolLinks(type.symbol).inferredClassType === type; - } - /** * Syntactically and semantically checks a call or new expression. * @param node The call/new expression to be checked. From 4ead3ff2a5520bb9d30d6beb128855166bd44779 Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Fri, 18 Jan 2019 15:32:56 -0800 Subject: [PATCH 8/8] remove circularity guards that aren't hit anymore --- src/compiler/checker.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 63561b42adfd8..49c26e67f9076 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8687,24 +8687,15 @@ namespace ts { * the type of this reference is just the type of the value we resolved to. */ function getJSDocTypeReference(node: NodeWithTypeArguments, symbol: Symbol, typeArguments: Type[] | undefined): Type | undefined { - if (!pushTypeResolution(symbol, TypeSystemPropertyName.JSDocTypeReference)) { - return errorType; - } - const staticType = getTypeOfSymbol(symbol); - // In the case of an assignment of a function expression (binary expressions, variable declarations, etc.), we will get the // correct instance type for the symbol on the LHS by finding the type for RHS. For example if we want to get the type of the symbol `foo`: // var foo = function() {} // We will find the static type of the assigned anonymous function. + const staticType = getTypeOfSymbol(symbol); const instanceType = staticType.symbol && staticType.symbol !== symbol && // Make sure this is an assignment like expression by checking that symbol -> type -> symbol doesn't roundtrips. getTypeReferenceTypeWorker(node, staticType.symbol, typeArguments); // Get the instance type of the RHS symbol. - if (!popTypeResolution()) { - getSymbolLinks(symbol).resolvedJSDocType = errorType; - error(node, Diagnostics.JSDoc_type_0_circularly_references_itself, symbolToString(symbol)); - return errorType; - } if (instanceType) { return getSymbolLinks(symbol).resolvedJSDocType = instanceType; }