From 12cd15c8677d2cb5cc9bf0ffdb7461ca1335d983 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 28 Apr 2020 10:42:24 -0700 Subject: [PATCH] this: undefined in modules (#37784) It's always supposed to have been this way, but I was worried about how breaky the change would be when adding globalThisType. This PR is experiment to see how much. Fixes #35882 maybe --- src/compiler/checker.ts | 4 ++ ...sxFactoryDeclarationsLocalTypes.errors.txt | 8 +++- ...neJsxFactoryDeclarationsLocalTypes.symbols | 1 - ...lineJsxFactoryDeclarationsLocalTypes.types | 2 +- ...InInvalidContextsExternalModule.errors.txt | 4 +- ...hisInInvalidContextsExternalModule.symbols | 1 - .../thisInInvalidContextsExternalModule.types | 2 +- .../reference/topLevelLambda4.errors.txt | 7 ++++ .../reference/topLevelLambda4.symbols | 3 -- .../baselines/reference/topLevelLambda4.types | 10 ++--- .../tsxAttributeResolution15.errors.txt | 6 +-- .../tsxAttributeResolution15.symbols | 1 - .../reference/tsxAttributeResolution15.types | 2 +- .../tsxSpreadAttributesResolution4.errors.txt | 40 +++++++++++++++++++ .../tsxSpreadAttributesResolution4.symbols | 1 - .../tsxSpreadAttributesResolution4.types | 2 +- 16 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 tests/baselines/reference/topLevelLambda4.errors.txt create mode 100644 tests/baselines/reference/tsxSpreadAttributesResolution4.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 93276c42cb3..b0527ec70b2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21660,6 +21660,10 @@ namespace ts { const fileSymbol = getSymbolOfNode(container); return fileSymbol && getTypeOfSymbol(fileSymbol); } + else if (container.externalModuleIndicator) { + // TODO: Maybe issue a better error than 'object is possibly undefined' + return undefinedType; + } else if (includeGlobalThis) { return getTypeOfSymbol(globalThisSymbol); } diff --git a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.errors.txt b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.errors.txt index a2d542ffb69..caced97b3e8 100644 --- a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.errors.txt +++ b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.errors.txt @@ -1,3 +1,5 @@ +tests/cases/conformance/jsx/inline/component.tsx(4,136): error TS2609: JSX spread child must be an array type. +tests/cases/conformance/jsx/inline/component.tsx(4,140): error TS2532: Object is possibly 'undefined'. tests/cases/conformance/jsx/inline/index.tsx(5,1): error TS2741: Property '__predomBrand' is missing in type 'import("tests/cases/conformance/jsx/inline/renderer").dom.JSX.Element' but required in type 'import("tests/cases/conformance/jsx/inline/renderer2").predom.JSX.Element'. tests/cases/conformance/jsx/inline/index.tsx(21,22): error TS2786: 'MySFC' cannot be used as a JSX component. Its return type 'import("tests/cases/conformance/jsx/inline/renderer2").predom.JSX.Element' is not a valid JSX element. @@ -53,11 +55,15 @@ tests/cases/conformance/jsx/inline/index.tsx(24,48): error TS2322: Type 'import( } } export function predom(): predom.JSX.Element; -==== tests/cases/conformance/jsx/inline/component.tsx (0 errors) ==== +==== tests/cases/conformance/jsx/inline/component.tsx (2 errors) ==== /** @jsx predom */ import { predom } from "./renderer2" export const MySFC = (props: {x: number, y: number, children?: predom.JSX.Element[]}) =>
{props.x} + {props.y} = {props.x + props.y}{...this.props.children}
; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2609: JSX spread child must be an array type. + ~~~~ +!!! error TS2532: Object is possibly 'undefined'. export class MyClass implements predom.JSX.Element { __predomBrand!: void; diff --git a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols index c53ac6b1948..25af733e40f 100644 --- a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols +++ b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols @@ -127,7 +127,6 @@ export const MySFC = (props: {x: number, y: number, children?: predom.JSX.Elemen >props.y : Symbol(y, Decl(component.tsx, 3, 40)) >props : Symbol(props, Decl(component.tsx, 3, 22)) >y : Symbol(y, Decl(component.tsx, 3, 40)) ->this : Symbol(globalThis) >p : Symbol(predom.JSX.IntrinsicElements, Decl(renderer2.d.ts, 1, 19)) export class MyClass implements predom.JSX.Element { diff --git a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types index c9f7d4c2d8d..38bcc1898eb 100644 --- a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types +++ b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types @@ -99,7 +99,7 @@ export const MySFC = (props: {x: number, y: number, children?: predom.JSX.Elemen >y : number >this.props.children : any >this.props : any ->this : typeof globalThis +>this : undefined >props : any >children : any >p : any diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index 4cfd109b00e..18f0e314a8a 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'typeof globalThis' is not a constructor function type. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'undefined' is not a constructor function type. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(44,9): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(45,9): error TS2332: 'this' cannot be referenced in current location. @@ -58,7 +58,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod class ErrClass3 extends this { ~~~~ -!!! error TS2507: Type 'typeof globalThis' is not a constructor function type. +!!! error TS2507: Type 'undefined' is not a constructor function type. } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols b/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols index ad52fbdabeb..9cf261fa672 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols @@ -69,7 +69,6 @@ genericFunc