From 132638b2aaa0273f7cf8a16b8cd9fc0bca3f5675 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 17 Feb 2023 15:21:27 -0800 Subject: [PATCH 1/4] Add test --- .../declarationEmitGlobalThisPreserved.js | 292 ++++++++++ ...declarationEmitGlobalThisPreserved.symbols | 502 +++++++++++++++++ .../declarationEmitGlobalThisPreserved.types | 524 ++++++++++++++++++ .../declarationEmitGlobalThisPreserved.ts | 108 ++++ 4 files changed, 1426 insertions(+) create mode 100644 tests/baselines/reference/declarationEmitGlobalThisPreserved.js create mode 100644 tests/baselines/reference/declarationEmitGlobalThisPreserved.symbols create mode 100644 tests/baselines/reference/declarationEmitGlobalThisPreserved.types create mode 100644 tests/cases/compiler/declarationEmitGlobalThisPreserved.ts diff --git a/tests/baselines/reference/declarationEmitGlobalThisPreserved.js b/tests/baselines/reference/declarationEmitGlobalThisPreserved.js new file mode 100644 index 0000000000000..ad6365ec046f5 --- /dev/null +++ b/tests/baselines/reference/declarationEmitGlobalThisPreserved.js @@ -0,0 +1,292 @@ +//// [declarationEmitGlobalThisPreserved.ts] +// Adding this makes tooltips fail too. +// declare global { +// namespace isNaN { +// const prop: number; +// } +// } + +// Broken inference cases. + +export const a1 = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN; +export const a2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN; +export const a3 = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar; +export const a4 = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN; + +export const aObj = { + a1: (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN, + a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN, + a3: (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar, + a4: (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN, +} + +export type a4Return = ReturnType>; +export type a4oReturn = ReturnType>; + +export const b1 = (isNaN: typeof globalThis.isNaN) => isNaN; +export const b2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN; +export const b3 = (isNaN: number, bar: typeof globalThis.isNaN) => bar; +export const b4 = (isNaN: number) => globalThis.isNaN; + +export const bObj = { + b1: (isNaN: typeof globalThis.isNaN) => isNaN, + b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN, + b3: (isNaN: number, bar: typeof globalThis.isNaN) => bar, + b4: (isNaN: number) => globalThis.isNaN, +} + +export type b4Return = ReturnType>; +export type b4oReturn = ReturnType>; + +export function c1(isNaN: typeof globalThis.isNaN) { return isNaN } +export function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN } +export function c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar } +export function c4(isNaN: number) { return globalThis.isNaN; } + +export const cObj = { + c1(isNaN: typeof globalThis.isNaN) { return isNaN }, + c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN }, + c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar }, + c4(isNaN: number) { return globalThis.isNaN; }, +} + +export type c4Return = ReturnType>; +export type c4oReturn = ReturnType>; + +export function d1() { + const fn = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN; + return function() { return fn }; +} + +export function d2() { + const fn = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN; + return function() { return fn }; +} + +export function d3() { + const fn = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar; + return function() { return fn }; +} + +export function d4() { + const fn = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN; + return function() { return fn }; +} + +export type d4Return = ReturnType>>>; + +export class A { + method1(isNaN: typeof globalThis.isNaN) { return isNaN } + method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN } + method3(isNaN: number, bar: typeof globalThis.isNaN) { return bar } + method4(isNaN: number) { return globalThis.isNaN; } +} + +export function fromParameter(isNaN: number, bar: typeof globalThis.isNaN) { + return function() { return { bar } }; +} + +// Non-inference cases. + +export const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN = (isNaN) => isNaN; + +export function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN { + return isNaN; +}; + +export type AsObjectProperty = { + isNaN: typeof globalThis.isNaN; +} + +export class AsClassProperty { + isNaN?: typeof globalThis.isNaN; +} + +export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; + + + + + +//// [declarationEmitGlobalThisPreserved.d.ts] +export declare const a1: (isNaN: typeof isNaN) => typeof isNaN; +export declare const a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; +export declare const a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; +export declare const a4: (isNaN: number) => typeof isNaN; +export declare const aObj: { + a1: (isNaN: typeof isNaN) => typeof isNaN; + a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; + a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; + a4: (isNaN: number) => typeof isNaN; +}; +export type a4Return = ReturnType>; +export type a4oReturn = ReturnType>; +export declare const b1: (isNaN: typeof isNaN) => typeof isNaN; +export declare const b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; +export declare const b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; +export declare const b4: (isNaN: number) => typeof isNaN; +export declare const bObj: { + b1: (isNaN: typeof isNaN) => typeof isNaN; + b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; + b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; + b4: (isNaN: number) => typeof isNaN; +}; +export type b4Return = ReturnType>; +export type b4oReturn = ReturnType>; +export declare function c1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; +export declare function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN; +export declare function c3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; +export declare function c4(isNaN: number): typeof globalThis.isNaN; +export declare const cObj: { + c1(isNaN: typeof isNaN): typeof isNaN; + c2(isNaN: typeof isNaN, bar?: typeof isNaN): typeof isNaN; + c3(isNaN: number, bar: typeof isNaN): typeof isNaN; + c4(isNaN: number): typeof isNaN; +}; +export type c4Return = ReturnType>; +export type c4oReturn = ReturnType>; +export declare function d1(): () => (isNaN: typeof isNaN) => typeof isNaN; +export declare function d2(): () => (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; +export declare function d3(): () => (isNaN: number, bar: typeof isNaN) => typeof isNaN; +export declare function d4(): () => (isNaN: number) => typeof isNaN; +export type d4Return = ReturnType>>>; +export declare class A { + method1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; + method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN; + method3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; + method4(isNaN: number): typeof globalThis.isNaN; +} +export declare function fromParameter(isNaN: number, bar: typeof globalThis.isNaN): () => { + bar: typeof globalThis.isNaN; +}; +export declare const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; +export declare function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; +export type AsObjectProperty = { + isNaN: typeof globalThis.isNaN; +}; +export declare class AsClassProperty { + isNaN?: typeof globalThis.isNaN; +} +export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; + + +//// [DtsFileErrors] + + +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(1,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(2,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(6,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(7,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(11,35): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(12,36): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(13,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(14,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(18,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(19,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(23,35): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(24,36): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(30,8): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(31,8): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(36,36): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(37,38): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(38,38): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(41,35): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. + + +==== tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts (18 errors) ==== + export declare const a1: (isNaN: typeof isNaN) => typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + export declare const a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + export declare const a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; + export declare const a4: (isNaN: number) => typeof isNaN; + export declare const aObj: { + a1: (isNaN: typeof isNaN) => typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; + a4: (isNaN: number) => typeof isNaN; + }; + export type a4Return = ReturnType>; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. + export type a4oReturn = ReturnType>; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. + export declare const b1: (isNaN: typeof isNaN) => typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + export declare const b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + export declare const b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; + export declare const b4: (isNaN: number) => typeof isNaN; + export declare const bObj: { + b1: (isNaN: typeof isNaN) => typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; + b4: (isNaN: number) => typeof isNaN; + }; + export type b4Return = ReturnType>; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. + export type b4oReturn = ReturnType>; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. + export declare function c1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; + export declare function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN; + export declare function c3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; + export declare function c4(isNaN: number): typeof globalThis.isNaN; + export declare const cObj: { + c1(isNaN: typeof isNaN): typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + c2(isNaN: typeof isNaN, bar?: typeof isNaN): typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + c3(isNaN: number, bar: typeof isNaN): typeof isNaN; + c4(isNaN: number): typeof isNaN; + }; + export type c4Return = ReturnType>; + export type c4oReturn = ReturnType>; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. + export declare function d1(): () => (isNaN: typeof isNaN) => typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + export declare function d2(): () => (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. + export declare function d3(): () => (isNaN: number, bar: typeof isNaN) => typeof isNaN; + export declare function d4(): () => (isNaN: number) => typeof isNaN; + export type d4Return = ReturnType>>>; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. + export declare class A { + method1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; + method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN; + method3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; + method4(isNaN: number): typeof globalThis.isNaN; + } + export declare function fromParameter(isNaN: number, bar: typeof globalThis.isNaN): () => { + bar: typeof globalThis.isNaN; + }; + export declare const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; + export declare function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; + export type AsObjectProperty = { + isNaN: typeof globalThis.isNaN; + }; + export declare class AsClassProperty { + isNaN?: typeof globalThis.isNaN; + } + export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitGlobalThisPreserved.symbols b/tests/baselines/reference/declarationEmitGlobalThisPreserved.symbols new file mode 100644 index 0000000000000..039035bc72472 --- /dev/null +++ b/tests/baselines/reference/declarationEmitGlobalThisPreserved.symbols @@ -0,0 +1,502 @@ +=== tests/cases/compiler/declarationEmitGlobalThisPreserved.ts === +// Adding this makes tooltips fail too. +// declare global { +// namespace isNaN { +// const prop: number; +// } +// } + +// Broken inference cases. + +export const a1 = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN; +>a1 : Symbol(a1, Decl(declarationEmitGlobalThisPreserved.ts, 9, 12)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 9, 19)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 9, 19)) + +export const a2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN; +>a2 : Symbol(a2, Decl(declarationEmitGlobalThisPreserved.ts, 10, 12)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 10, 19)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 10, 50)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 10, 50)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 10, 19)) + +export const a3 = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar; +>a3 : Symbol(a3, Decl(declarationEmitGlobalThisPreserved.ts, 11, 12)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 11, 19)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 11, 33)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 11, 33)) + +export const a4 = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN; +>a4 : Symbol(a4, Decl(declarationEmitGlobalThisPreserved.ts, 12, 12)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 12, 19)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) + +export const aObj = { +>aObj : Symbol(aObj, Decl(declarationEmitGlobalThisPreserved.ts, 14, 12)) + + a1: (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN, +>a1 : Symbol(a1, Decl(declarationEmitGlobalThisPreserved.ts, 14, 21)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 15, 9)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 15, 9)) + + a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN, +>a2 : Symbol(a2, Decl(declarationEmitGlobalThisPreserved.ts, 15, 75)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 16, 9)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 16, 40)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 16, 40)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 16, 9)) + + a3: (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar, +>a3 : Symbol(a3, Decl(declarationEmitGlobalThisPreserved.ts, 16, 113)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 17, 9)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 17, 23)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 17, 23)) + + a4: (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN, +>a4 : Symbol(a4, Decl(declarationEmitGlobalThisPreserved.ts, 17, 86)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 18, 9)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +} + +export type a4Return = ReturnType>; +>a4Return : Symbol(a4Return, Decl(declarationEmitGlobalThisPreserved.ts, 19, 1)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>a4 : Symbol(a4, Decl(declarationEmitGlobalThisPreserved.ts, 12, 12)) + +export type a4oReturn = ReturnType>; +>a4oReturn : Symbol(a4oReturn, Decl(declarationEmitGlobalThisPreserved.ts, 21, 57)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>aObj : Symbol(aObj, Decl(declarationEmitGlobalThisPreserved.ts, 14, 12)) + +export const b1 = (isNaN: typeof globalThis.isNaN) => isNaN; +>b1 : Symbol(b1, Decl(declarationEmitGlobalThisPreserved.ts, 24, 12)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 24, 19)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 24, 19)) + +export const b2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN; +>b2 : Symbol(b2, Decl(declarationEmitGlobalThisPreserved.ts, 25, 12)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 25, 19)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 25, 50)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 25, 50)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 25, 19)) + +export const b3 = (isNaN: number, bar: typeof globalThis.isNaN) => bar; +>b3 : Symbol(b3, Decl(declarationEmitGlobalThisPreserved.ts, 26, 12)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 26, 19)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 26, 33)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 26, 33)) + +export const b4 = (isNaN: number) => globalThis.isNaN; +>b4 : Symbol(b4, Decl(declarationEmitGlobalThisPreserved.ts, 27, 12)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 27, 19)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) + +export const bObj = { +>bObj : Symbol(bObj, Decl(declarationEmitGlobalThisPreserved.ts, 29, 12)) + + b1: (isNaN: typeof globalThis.isNaN) => isNaN, +>b1 : Symbol(b1, Decl(declarationEmitGlobalThisPreserved.ts, 29, 21)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 30, 9)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 30, 9)) + + b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN, +>b2 : Symbol(b2, Decl(declarationEmitGlobalThisPreserved.ts, 30, 50)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 31, 9)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 31, 40)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 31, 40)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 31, 9)) + + b3: (isNaN: number, bar: typeof globalThis.isNaN) => bar, +>b3 : Symbol(b3, Decl(declarationEmitGlobalThisPreserved.ts, 31, 88)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 32, 9)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 32, 23)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 32, 23)) + + b4: (isNaN: number) => globalThis.isNaN, +>b4 : Symbol(b4, Decl(declarationEmitGlobalThisPreserved.ts, 32, 61)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 33, 9)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +} + +export type b4Return = ReturnType>; +>b4Return : Symbol(b4Return, Decl(declarationEmitGlobalThisPreserved.ts, 34, 1)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>b4 : Symbol(b4, Decl(declarationEmitGlobalThisPreserved.ts, 27, 12)) + +export type b4oReturn = ReturnType>; +>b4oReturn : Symbol(b4oReturn, Decl(declarationEmitGlobalThisPreserved.ts, 36, 57)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>bObj : Symbol(bObj, Decl(declarationEmitGlobalThisPreserved.ts, 29, 12)) + +export function c1(isNaN: typeof globalThis.isNaN) { return isNaN } +>c1 : Symbol(c1, Decl(declarationEmitGlobalThisPreserved.ts, 37, 66)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 39, 19)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 39, 19)) + +export function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN } +>c2 : Symbol(c2, Decl(declarationEmitGlobalThisPreserved.ts, 39, 67)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 40, 19)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 40, 50)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 40, 50)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 40, 19)) + +export function c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar } +>c3 : Symbol(c3, Decl(declarationEmitGlobalThisPreserved.ts, 40, 105)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 41, 19)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 41, 33)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 41, 33)) + +export function c4(isNaN: number) { return globalThis.isNaN; } +>c4 : Symbol(c4, Decl(declarationEmitGlobalThisPreserved.ts, 41, 78)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 42, 19)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) + +export const cObj = { +>cObj : Symbol(cObj, Decl(declarationEmitGlobalThisPreserved.ts, 44, 12)) + + c1(isNaN: typeof globalThis.isNaN) { return isNaN }, +>c1 : Symbol(c1, Decl(declarationEmitGlobalThisPreserved.ts, 44, 21)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 45, 7)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 45, 7)) + + c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN }, +>c2 : Symbol(c2, Decl(declarationEmitGlobalThisPreserved.ts, 45, 56)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 46, 7)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 46, 38)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 46, 38)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 46, 7)) + + c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar }, +>c3 : Symbol(c3, Decl(declarationEmitGlobalThisPreserved.ts, 46, 94)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 47, 7)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 47, 21)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 47, 21)) + + c4(isNaN: number) { return globalThis.isNaN; }, +>c4 : Symbol(c4, Decl(declarationEmitGlobalThisPreserved.ts, 47, 67)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 48, 7)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +} + +export type c4Return = ReturnType>; +>c4Return : Symbol(c4Return, Decl(declarationEmitGlobalThisPreserved.ts, 49, 1)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>c4 : Symbol(c4, Decl(declarationEmitGlobalThisPreserved.ts, 41, 78)) + +export type c4oReturn = ReturnType>; +>c4oReturn : Symbol(c4oReturn, Decl(declarationEmitGlobalThisPreserved.ts, 51, 57)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>cObj : Symbol(cObj, Decl(declarationEmitGlobalThisPreserved.ts, 44, 12)) + +export function d1() { +>d1 : Symbol(d1, Decl(declarationEmitGlobalThisPreserved.ts, 52, 66)) + + const fn = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN; +>fn : Symbol(fn, Decl(declarationEmitGlobalThisPreserved.ts, 55, 9)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 55, 16)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 55, 16)) + + return function() { return fn }; +>fn : Symbol(fn, Decl(declarationEmitGlobalThisPreserved.ts, 55, 9)) +} + +export function d2() { +>d2 : Symbol(d2, Decl(declarationEmitGlobalThisPreserved.ts, 57, 1)) + + const fn = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN; +>fn : Symbol(fn, Decl(declarationEmitGlobalThisPreserved.ts, 60, 9)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 60, 16)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 60, 47)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 60, 47)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 60, 16)) + + return function() { return fn }; +>fn : Symbol(fn, Decl(declarationEmitGlobalThisPreserved.ts, 60, 9)) +} + +export function d3() { +>d3 : Symbol(d3, Decl(declarationEmitGlobalThisPreserved.ts, 62, 1)) + + const fn = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar; +>fn : Symbol(fn, Decl(declarationEmitGlobalThisPreserved.ts, 65, 9)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 65, 16)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 65, 30)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 65, 30)) + + return function() { return fn }; +>fn : Symbol(fn, Decl(declarationEmitGlobalThisPreserved.ts, 65, 9)) +} + +export function d4() { +>d4 : Symbol(d4, Decl(declarationEmitGlobalThisPreserved.ts, 67, 1)) + + const fn = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN; +>fn : Symbol(fn, Decl(declarationEmitGlobalThisPreserved.ts, 70, 9)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 70, 16)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) + + return function() { return fn }; +>fn : Symbol(fn, Decl(declarationEmitGlobalThisPreserved.ts, 70, 9)) +} + +export type d4Return = ReturnType>>>; +>d4Return : Symbol(d4Return, Decl(declarationEmitGlobalThisPreserved.ts, 72, 1)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>d4 : Symbol(d4, Decl(declarationEmitGlobalThisPreserved.ts, 67, 1)) + +export class A { +>A : Symbol(A, Decl(declarationEmitGlobalThisPreserved.ts, 74, 81)) + + method1(isNaN: typeof globalThis.isNaN) { return isNaN } +>method1 : Symbol(A.method1, Decl(declarationEmitGlobalThisPreserved.ts, 76, 16)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 77, 12)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 77, 12)) + + method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN } +>method2 : Symbol(A.method2, Decl(declarationEmitGlobalThisPreserved.ts, 77, 60)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 78, 12)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 78, 43)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 78, 43)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 78, 12)) + + method3(isNaN: number, bar: typeof globalThis.isNaN) { return bar } +>method3 : Symbol(A.method3, Decl(declarationEmitGlobalThisPreserved.ts, 78, 98)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 79, 12)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 79, 26)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 79, 26)) + + method4(isNaN: number) { return globalThis.isNaN; } +>method4 : Symbol(A.method4, Decl(declarationEmitGlobalThisPreserved.ts, 79, 71)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 80, 12)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +} + +export function fromParameter(isNaN: number, bar: typeof globalThis.isNaN) { +>fromParameter : Symbol(fromParameter, Decl(declarationEmitGlobalThisPreserved.ts, 81, 1)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 83, 30)) +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 83, 44)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) + + return function() { return { bar } }; +>bar : Symbol(bar, Decl(declarationEmitGlobalThisPreserved.ts, 84, 32)) +} + +// Non-inference cases. + +export const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN = (isNaN) => isNaN; +>explicitlyTypedVariable : Symbol(explicitlyTypedVariable, Decl(declarationEmitGlobalThisPreserved.ts, 89, 12)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 89, 39)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 89, 101)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 89, 101)) + +export function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN { +>explicitlyTypedFunction : Symbol(explicitlyTypedFunction, Decl(declarationEmitGlobalThisPreserved.ts, 89, 117)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 91, 40)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) + + return isNaN; +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 91, 40)) + +}; + +export type AsObjectProperty = { +>AsObjectProperty : Symbol(AsObjectProperty, Decl(declarationEmitGlobalThisPreserved.ts, 93, 2)) + + isNaN: typeof globalThis.isNaN; +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 95, 32)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +} + +export class AsClassProperty { +>AsClassProperty : Symbol(AsClassProperty, Decl(declarationEmitGlobalThisPreserved.ts, 97, 1)) + + isNaN?: typeof globalThis.isNaN; +>isNaN : Symbol(AsClassProperty.isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 99, 30)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +} + +export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; +>AsFunctionType : Symbol(AsFunctionType, Decl(declarationEmitGlobalThisPreserved.ts, 101, 1)) +>isNaN : Symbol(isNaN, Decl(declarationEmitGlobalThisPreserved.ts, 103, 30)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis.isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) +>globalThis : Symbol(globalThis) +>isNaN : Symbol(isNaN, Decl(lib.es5.d.ts, --, --)) + + diff --git a/tests/baselines/reference/declarationEmitGlobalThisPreserved.types b/tests/baselines/reference/declarationEmitGlobalThisPreserved.types new file mode 100644 index 0000000000000..ad13ce25fdf88 --- /dev/null +++ b/tests/baselines/reference/declarationEmitGlobalThisPreserved.types @@ -0,0 +1,524 @@ +=== tests/cases/compiler/declarationEmitGlobalThisPreserved.ts === +// Adding this makes tooltips fail too. +// declare global { +// namespace isNaN { +// const prop: number; +// } +// } + +// Broken inference cases. + +export const a1 = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN; +>a1 : (isNaN: (number: number) => boolean) => (number: number) => boolean +>(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN : (isNaN: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>isNaN : (number: number) => boolean + +export const a2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN; +>a2 : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar ?? isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>isNaN : (number: number) => boolean + +export const a3 = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar; +>a3 : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>isNaN : number +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean + +export const a4 = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN; +>a4 : (isNaN: number) => (number: number) => boolean +>(isNaN: number): typeof globalThis.isNaN => globalThis.isNaN : (isNaN: number) => (number: number) => boolean +>isNaN : number +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean + +export const aObj = { +>aObj : { a1: (isNaN: (number: number) => boolean) => (number: number) => boolean; a2: (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean; a3: (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean; a4: (isNaN: number) => (number: number) => boolean; } +>{ a1: (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN, a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN, a3: (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar, a4: (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN,} : { a1: (isNaN: (number: number) => boolean) => (number: number) => boolean; a2: (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean; a3: (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean; a4: (isNaN: number) => (number: number) => boolean; } + + a1: (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN, +>a1 : (isNaN: (number: number) => boolean) => (number: number) => boolean +>(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN : (isNaN: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>isNaN : (number: number) => boolean + + a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN, +>a2 : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar ?? isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>isNaN : (number: number) => boolean + + a3: (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar, +>a3 : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>isNaN : number +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean + + a4: (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN, +>a4 : (isNaN: number) => (number: number) => boolean +>(isNaN: number): typeof globalThis.isNaN => globalThis.isNaN : (isNaN: number) => (number: number) => boolean +>isNaN : number +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +} + +export type a4Return = ReturnType>; +>a4Return : boolean +>a4 : (isNaN: number) => (number: number) => boolean + +export type a4oReturn = ReturnType>; +>a4oReturn : boolean +>aObj : { a1: (isNaN: (number: number) => boolean) => (number: number) => boolean; a2: (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean; a3: (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean; a4: (isNaN: number) => (number: number) => boolean; } + +export const b1 = (isNaN: typeof globalThis.isNaN) => isNaN; +>b1 : (isNaN: (number: number) => boolean) => (number: number) => boolean +>(isNaN: typeof globalThis.isNaN) => isNaN : (isNaN: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>isNaN : (number: number) => boolean + +export const b2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN; +>b2 : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar ?? isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>isNaN : (number: number) => boolean + +export const b3 = (isNaN: number, bar: typeof globalThis.isNaN) => bar; +>b3 : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>(isNaN: number, bar: typeof globalThis.isNaN) => bar : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>isNaN : number +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean + +export const b4 = (isNaN: number) => globalThis.isNaN; +>b4 : (isNaN: number) => (number: number) => boolean +>(isNaN: number) => globalThis.isNaN : (isNaN: number) => (number: number) => boolean +>isNaN : number +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean + +export const bObj = { +>bObj : { b1: (isNaN: (number: number) => boolean) => (number: number) => boolean; b2: (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean; b3: (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean; b4: (isNaN: number) => (number: number) => boolean; } +>{ b1: (isNaN: typeof globalThis.isNaN) => isNaN, b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN, b3: (isNaN: number, bar: typeof globalThis.isNaN) => bar, b4: (isNaN: number) => globalThis.isNaN,} : { b1: (isNaN: (number: number) => boolean) => (number: number) => boolean; b2: (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean; b3: (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean; b4: (isNaN: number) => (number: number) => boolean; } + + b1: (isNaN: typeof globalThis.isNaN) => isNaN, +>b1 : (isNaN: (number: number) => boolean) => (number: number) => boolean +>(isNaN: typeof globalThis.isNaN) => isNaN : (isNaN: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>isNaN : (number: number) => boolean + + b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN, +>b2 : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar ?? isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>isNaN : (number: number) => boolean + + b3: (isNaN: number, bar: typeof globalThis.isNaN) => bar, +>b3 : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>(isNaN: number, bar: typeof globalThis.isNaN) => bar : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>isNaN : number +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean + + b4: (isNaN: number) => globalThis.isNaN, +>b4 : (isNaN: number) => (number: number) => boolean +>(isNaN: number) => globalThis.isNaN : (isNaN: number) => (number: number) => boolean +>isNaN : number +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +} + +export type b4Return = ReturnType>; +>b4Return : boolean +>b4 : (isNaN: number) => (number: number) => boolean + +export type b4oReturn = ReturnType>; +>b4oReturn : boolean +>bObj : { b1: (isNaN: (number: number) => boolean) => (number: number) => boolean; b2: (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean; b3: (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean; b4: (isNaN: number) => (number: number) => boolean; } + +export function c1(isNaN: typeof globalThis.isNaN) { return isNaN } +>c1 : (isNaN: typeof globalThis.isNaN) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>isNaN : (number: number) => boolean + +export function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN } +>c2 : (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar ?? isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>isNaN : (number: number) => boolean + +export function c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar } +>c3 : (isNaN: number, bar: typeof globalThis.isNaN) => (number: number) => boolean +>isNaN : number +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean + +export function c4(isNaN: number) { return globalThis.isNaN; } +>c4 : (isNaN: number) => (number: number) => boolean +>isNaN : number +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean + +export const cObj = { +>cObj : { c1(isNaN: (number: number) => boolean): (number: number) => boolean; c2(isNaN: (number: number) => boolean, bar?: (number: number) => boolean): (number: number) => boolean; c3(isNaN: number, bar: (number: number) => boolean): (number: number) => boolean; c4(isNaN: number): (number: number) => boolean; } +>{ c1(isNaN: typeof globalThis.isNaN) { return isNaN }, c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN }, c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar }, c4(isNaN: number) { return globalThis.isNaN; },} : { c1(isNaN: (number: number) => boolean): (number: number) => boolean; c2(isNaN: (number: number) => boolean, bar?: (number: number) => boolean): (number: number) => boolean; c3(isNaN: number, bar: (number: number) => boolean): (number: number) => boolean; c4(isNaN: number): (number: number) => boolean; } + + c1(isNaN: typeof globalThis.isNaN) { return isNaN }, +>c1 : (isNaN: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>isNaN : (number: number) => boolean + + c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN }, +>c2 : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar ?? isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>isNaN : (number: number) => boolean + + c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar }, +>c3 : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>isNaN : number +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean + + c4(isNaN: number) { return globalThis.isNaN; }, +>c4 : (isNaN: number) => (number: number) => boolean +>isNaN : number +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +} + +export type c4Return = ReturnType>; +>c4Return : boolean +>c4 : (isNaN: number) => (number: number) => boolean + +export type c4oReturn = ReturnType>; +>c4oReturn : boolean +>cObj : { c1(isNaN: (number: number) => boolean): (number: number) => boolean; c2(isNaN: (number: number) => boolean, bar?: (number: number) => boolean): (number: number) => boolean; c3(isNaN: number, bar: (number: number) => boolean): (number: number) => boolean; c4(isNaN: number): (number: number) => boolean; } + +export function d1() { +>d1 : () => () => (isNaN: (number: number) => boolean) => (number: number) => boolean + + const fn = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN; +>fn : (isNaN: (number: number) => boolean) => (number: number) => boolean +>(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN : (isNaN: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>isNaN : (number: number) => boolean + + return function() { return fn }; +>function() { return fn } : () => (isNaN: (number: number) => boolean) => (number: number) => boolean +>fn : (isNaN: (number: number) => boolean) => (number: number) => boolean +} + +export function d2() { +>d2 : () => () => (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean + + const fn = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN; +>fn : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar ?? isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>isNaN : (number: number) => boolean + + return function() { return fn }; +>function() { return fn } : () => (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +>fn : (isNaN: (number: number) => boolean, bar?: (number: number) => boolean) => (number: number) => boolean +} + +export function d3() { +>d3 : () => () => (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean + + const fn = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar; +>fn : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>isNaN : number +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean + + return function() { return fn }; +>function() { return fn } : () => (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +>fn : (isNaN: number, bar: (number: number) => boolean) => (number: number) => boolean +} + +export function d4() { +>d4 : () => () => (isNaN: number) => (number: number) => boolean + + const fn = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN; +>fn : (isNaN: number) => (number: number) => boolean +>(isNaN: number): typeof globalThis.isNaN => globalThis.isNaN : (isNaN: number) => (number: number) => boolean +>isNaN : number +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean + + return function() { return fn }; +>function() { return fn } : () => (isNaN: number) => (number: number) => boolean +>fn : (isNaN: number) => (number: number) => boolean +} + +export type d4Return = ReturnType>>>; +>d4Return : boolean +>d4 : () => () => (isNaN: number) => (number: number) => boolean + +export class A { +>A : A + + method1(isNaN: typeof globalThis.isNaN) { return isNaN } +>method1 : (isNaN: typeof globalThis.isNaN) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>isNaN : (number: number) => boolean + + method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN } +>method2 : (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar ?? isNaN : (number: number) => boolean +>bar : (number: number) => boolean +>isNaN : (number: number) => boolean + + method3(isNaN: number, bar: typeof globalThis.isNaN) { return bar } +>method3 : (isNaN: number, bar: typeof globalThis.isNaN) => (number: number) => boolean +>isNaN : number +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>bar : (number: number) => boolean + + method4(isNaN: number) { return globalThis.isNaN; } +>method4 : (isNaN: number) => (number: number) => boolean +>isNaN : number +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +} + +export function fromParameter(isNaN: number, bar: typeof globalThis.isNaN) { +>fromParameter : (isNaN: number, bar: typeof globalThis.isNaN) => () => { bar: (number: number) => boolean; } +>isNaN : number +>bar : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean + + return function() { return { bar } }; +>function() { return { bar } } : () => { bar: (number: number) => boolean; } +>{ bar } : { bar: (number: number) => boolean; } +>bar : (number: number) => boolean +} + +// Non-inference cases. + +export const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN = (isNaN) => isNaN; +>explicitlyTypedVariable : (isNaN: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>(isNaN) => isNaN : (isNaN: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>isNaN : (number: number) => boolean + +export function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN { +>explicitlyTypedFunction : (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean + + return isNaN; +>isNaN : (number: number) => boolean + +}; + +export type AsObjectProperty = { +>AsObjectProperty : { isNaN: typeof globalThis.isNaN; } + + isNaN: typeof globalThis.isNaN; +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +} + +export class AsClassProperty { +>AsClassProperty : AsClassProperty + + isNaN?: typeof globalThis.isNaN; +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +} + +export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; +>AsFunctionType : (isNaN: (number: number) => boolean) => (number: number) => boolean +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean +>globalThis.isNaN : (number: number) => boolean +>globalThis : typeof globalThis +>isNaN : (number: number) => boolean + + diff --git a/tests/cases/compiler/declarationEmitGlobalThisPreserved.ts b/tests/cases/compiler/declarationEmitGlobalThisPreserved.ts new file mode 100644 index 0000000000000..95e352fb6fa2f --- /dev/null +++ b/tests/cases/compiler/declarationEmitGlobalThisPreserved.ts @@ -0,0 +1,108 @@ +// @declaration: true +// @emitDeclarationOnly: true + +// Adding this makes tooltips fail too. +// declare global { +// namespace isNaN { +// const prop: number; +// } +// } + +// Broken inference cases. + +export const a1 = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN; +export const a2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN; +export const a3 = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar; +export const a4 = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN; + +export const aObj = { + a1: (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN, + a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN, + a3: (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar, + a4: (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN, +} + +export type a4Return = ReturnType>; +export type a4oReturn = ReturnType>; + +export const b1 = (isNaN: typeof globalThis.isNaN) => isNaN; +export const b2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN; +export const b3 = (isNaN: number, bar: typeof globalThis.isNaN) => bar; +export const b4 = (isNaN: number) => globalThis.isNaN; + +export const bObj = { + b1: (isNaN: typeof globalThis.isNaN) => isNaN, + b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN, + b3: (isNaN: number, bar: typeof globalThis.isNaN) => bar, + b4: (isNaN: number) => globalThis.isNaN, +} + +export type b4Return = ReturnType>; +export type b4oReturn = ReturnType>; + +export function c1(isNaN: typeof globalThis.isNaN) { return isNaN } +export function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN } +export function c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar } +export function c4(isNaN: number) { return globalThis.isNaN; } + +export const cObj = { + c1(isNaN: typeof globalThis.isNaN) { return isNaN }, + c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN }, + c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar }, + c4(isNaN: number) { return globalThis.isNaN; }, +} + +export type c4Return = ReturnType>; +export type c4oReturn = ReturnType>; + +export function d1() { + const fn = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN; + return function() { return fn }; +} + +export function d2() { + const fn = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN; + return function() { return fn }; +} + +export function d3() { + const fn = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar; + return function() { return fn }; +} + +export function d4() { + const fn = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN; + return function() { return fn }; +} + +export type d4Return = ReturnType>>>; + +export class A { + method1(isNaN: typeof globalThis.isNaN) { return isNaN } + method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN } + method3(isNaN: number, bar: typeof globalThis.isNaN) { return bar } + method4(isNaN: number) { return globalThis.isNaN; } +} + +export function fromParameter(isNaN: number, bar: typeof globalThis.isNaN) { + return function() { return { bar } }; +} + +// Non-inference cases. + +export const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN = (isNaN) => isNaN; + +export function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN { + return isNaN; +}; + +export type AsObjectProperty = { + isNaN: typeof globalThis.isNaN; +} + +export class AsClassProperty { + isNaN?: typeof globalThis.isNaN; +} + +export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; + From fafd048c14b11607e8881dbfadacbd1a8ce1de6e Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 17 Feb 2023 15:21:42 -0800 Subject: [PATCH 2/4] Ensure parameters are in scope when converting parameter/return types to type nodes --- src/compiler/checker.ts | 86 ++++++++- src/compiler/types.ts | 1 + .../declarationEmitGlobalThisPreserved.js | 170 +++--------------- .../declarationEmitGlobalThisPreserved.types | 4 +- ...InternalTypesProduceUniqueTypeParams.types | 4 +- ...enericTypeWithNonGenericBaseMisMatch.types | 2 +- .../parenthesizedContexualTyping2.types | 2 +- .../reference/recursiveTypesWithTypeof.types | 4 +- .../taggedTemplateContextualTyping1.types | 2 +- .../taggedTemplateContextualTyping2.types | 4 +- .../reference/targetTypeCastTest.types | 2 +- .../typeParametersInStaticMethods.types | 4 +- tests/baselines/reference/vardecl.types | 2 +- 13 files changed, 124 insertions(+), 163 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 70bad3767924f..19afee32933f1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7276,6 +7276,82 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const expandedParams = getExpandedParameters(signature, /*skipUnionExpanding*/ true)[0]; + + // For regular function/method declarations, the enclosing declaration will already be signature.declaration, + // so this is a no-op, but for arrow functions and function expressions, the enclosing declaration will be + // the declaration that the arrow function / function expression is assigned to. + // + // If the parameters or return type include "typeof globalThis.paramName", using the wrong scope will lead + // us to believe that we can emit "typeof paramName" instead, even though that would refer to the parameter, + // not the global. Make sure we are in the right scope by changing the enclosingDeclaration to the function. + // + // We can't use the declaration directly; it may be in another file and so we may lose access to symbols + // accessible to the current enclosing declaration, or gain access to symbols not accessible to the current + // enclosing declaration. To keep this chain accurate, insert a fake scope into the chain which makes the + // function's parameters visible. + // + // If the declaration is in a JS file, then we don't need to do this at all, as there are no annotations besides + // JSDoc, which are always outside the function declaration, so are not in the parameter scope. + let cleanup: (() => void) | undefined; + if ( + context.enclosingDeclaration + && signature.declaration + && signature.declaration !== context.enclosingDeclaration + && !isInJSFile(signature.declaration) + && some(expandedParams) + ) { + // As a performance optimization, share the symbol table between all faked scopes + // in this node builder chain. This is especially needed when we are working on an + // excessively deep type; if we don't do this, then we spend all of our time adding + // more and more scopes that need to be searched in isSymbolAccessible later. Since + // all we really want to do is to mark certain names as unavailable, we can just + // keep all of the names we're introducing in one large table and push/pop from it as + // needed; isSymbolAccessible will walk upward and find the closest "fake" scope, + // which will conveniently report on any and all faked scopes in the chain. + // + // It'd likely be better to store this somewhere else for isSymbolAccessible, but + // since that API _only_ uses the enclosing declaration (and its parents), this is + // seems like the best way to inject names into that search process. + const existingFakeScope = findAncestor(context.enclosingDeclaration, node => !!getNodeLinks(node).fakeScopeForSignatureDeclaration); + Debug.assertOptionalNode(existingFakeScope, isBlock); + + const locals = existingFakeScope?.locals ?? createSymbolTable(); + + let newLocals: __String[] | undefined; + for (const param of expandedParams) { + if (!locals.has(param.escapedName)) { + newLocals = append(newLocals, param.escapedName); + locals.set(param.escapedName, param); + } + } + + if (newLocals) { + function removeNewLocals() { + forEach(newLocals, s => locals.delete(s)); + } + + if (existingFakeScope) { + cleanup = removeNewLocals; + } + else { + // Use a Block for this; the type of the node doesn't matter so long as it + // has locals, and this is cheaper/easier than using a function-ish Node. + const fakeScope = parseNodeFactory.createBlock(emptyArray); + getNodeLinks(fakeScope).fakeScopeForSignatureDeclaration = true; + fakeScope.locals = locals; + + const saveEnclosingDeclaration = context.enclosingDeclaration; + setParent(fakeScope, saveEnclosingDeclaration); + context.enclosingDeclaration = fakeScope; + + cleanup = () => { + context.enclosingDeclaration = saveEnclosingDeclaration; + removeNewLocals(); + }; + } + } + } + // If the expanded parameter list had a variadic in a non-trailing position, don't expand it const parameters = (some(expandedParams, p => p !== expandedParams[expandedParams.length - 1] && !!(getCheckFlags(p) & CheckFlags.RestParameter)) ? signature.parameters : expandedParams).map(parameter => symbolToParameterDeclaration(parameter, context, kind === SyntaxKind.Constructor, options?.privateSymbolVisitor, options?.bundledImports)); const thisParameter = context.flags & NodeBuilderFlags.OmitThisParameter ? undefined : tryGetThisParameterDeclaration(signature, context); @@ -7331,6 +7407,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { node.typeArguments = factory.createNodeArray(typeArguments); } + cleanup?.(); return node; } @@ -7996,13 +8073,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return !(getObjectFlags(type) & ObjectFlags.Reference) || !isTypeReferenceNode(existing) || length(existing.typeArguments) >= getMinTypeArgumentCount((type as TypeReference).target.typeParameters); } + function getEnclosingDeclarationIgnoringFakeScope(enclosingDeclaration: Node) { + return findAncestor(enclosingDeclaration, n => !getNodeLinks(n).fakeScopeForSignatureDeclaration); + } + /** * Unlike `typeToTypeNodeHelper`, this handles setting up the `AllowUniqueESSymbolType` flag * so a `unique symbol` is returned when appropriate for the input symbol, rather than `typeof sym` */ function serializeTypeForDeclaration(context: NodeBuilderContext, type: Type, symbol: Symbol, enclosingDeclaration: Node | undefined, includePrivateSymbol?: (s: Symbol) => void, bundled?: boolean) { if (!isErrorType(type) && enclosingDeclaration) { - const declWithExistingAnnotation = getDeclarationWithTypeAnnotation(symbol, enclosingDeclaration); + const declWithExistingAnnotation = getDeclarationWithTypeAnnotation(symbol, getEnclosingDeclarationIgnoringFakeScope(enclosingDeclaration)); if (declWithExistingAnnotation && !isFunctionLikeDeclaration(declWithExistingAnnotation) && !isGetAccessorDeclaration(declWithExistingAnnotation)) { // try to reuse the existing annotation const existing = getEffectiveTypeAnnotationNode(declWithExistingAnnotation)!; @@ -8038,7 +8119,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function serializeReturnTypeForSignature(context: NodeBuilderContext, type: Type, signature: Signature, includePrivateSymbol?: (s: Symbol) => void, bundled?: boolean) { if (!isErrorType(type) && context.enclosingDeclaration) { const annotation = signature.declaration && getEffectiveReturnTypeNode(signature.declaration); - if (!!findAncestor(annotation, n => n === context.enclosingDeclaration) && annotation) { + const enclosingDeclarationIgnoringFakeScope = getEnclosingDeclarationIgnoringFakeScope(context.enclosingDeclaration); + if (!!findAncestor(annotation, n => n === enclosingDeclarationIgnoringFakeScope) && annotation) { const annotated = getTypeFromTypeNode(annotation); const thisInstantiated = annotated.flags & TypeFlags.TypeParameter && (annotated as TypeParameter).isThisType ? instantiateType(annotated, signature.mapper) : annotated; if (thisInstantiated === type && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(annotation, type)) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0a1128483f54e..aa013763ddba2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5997,6 +5997,7 @@ export interface NodeLinks { serializedTypes?: Map; // Collection of types serialized at this location decoratorSignature?: Signature; // Signature for decorator as if invoked by the runtime. parameterInitializerContainsUndefined?: boolean; // True if this is a parameter declaration whose type annotation contains "undefined". + fakeScopeForSignatureDeclaration?: boolean; // True if this is a fake scope injected into an enclosing declaration chain. } /** @internal */ diff --git a/tests/baselines/reference/declarationEmitGlobalThisPreserved.js b/tests/baselines/reference/declarationEmitGlobalThisPreserved.js index ad6365ec046f5..0736b594434cb 100644 --- a/tests/baselines/reference/declarationEmitGlobalThisPreserved.js +++ b/tests/baselines/reference/declarationEmitGlobalThisPreserved.js @@ -109,27 +109,27 @@ export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalTh //// [declarationEmitGlobalThisPreserved.d.ts] -export declare const a1: (isNaN: typeof isNaN) => typeof isNaN; -export declare const a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; -export declare const a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; -export declare const a4: (isNaN: number) => typeof isNaN; +export declare const a1: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; +export declare const a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => typeof globalThis.isNaN; +export declare const a3: (isNaN: number, bar: typeof globalThis.isNaN) => typeof globalThis.isNaN; +export declare const a4: (isNaN: number) => typeof globalThis.isNaN; export declare const aObj: { - a1: (isNaN: typeof isNaN) => typeof isNaN; - a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; - a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; - a4: (isNaN: number) => typeof isNaN; + a1: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; + a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => typeof globalThis.isNaN; + a3: (isNaN: number, bar: typeof globalThis.isNaN) => typeof globalThis.isNaN; + a4: (isNaN: number) => typeof globalThis.isNaN; }; export type a4Return = ReturnType>; export type a4oReturn = ReturnType>; -export declare const b1: (isNaN: typeof isNaN) => typeof isNaN; -export declare const b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; -export declare const b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; -export declare const b4: (isNaN: number) => typeof isNaN; +export declare const b1: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; +export declare const b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => typeof globalThis.isNaN; +export declare const b3: (isNaN: number, bar: typeof globalThis.isNaN) => typeof globalThis.isNaN; +export declare const b4: (isNaN: number) => typeof globalThis.isNaN; export declare const bObj: { - b1: (isNaN: typeof isNaN) => typeof isNaN; - b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; - b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; - b4: (isNaN: number) => typeof isNaN; + b1: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; + b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => typeof globalThis.isNaN; + b3: (isNaN: number, bar: typeof globalThis.isNaN) => typeof globalThis.isNaN; + b4: (isNaN: number) => typeof globalThis.isNaN; }; export type b4Return = ReturnType>; export type b4oReturn = ReturnType>; @@ -138,17 +138,17 @@ export declare function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalTh export declare function c3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; export declare function c4(isNaN: number): typeof globalThis.isNaN; export declare const cObj: { - c1(isNaN: typeof isNaN): typeof isNaN; - c2(isNaN: typeof isNaN, bar?: typeof isNaN): typeof isNaN; - c3(isNaN: number, bar: typeof isNaN): typeof isNaN; - c4(isNaN: number): typeof isNaN; + c1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; + c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN; + c3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; + c4(isNaN: number): typeof globalThis.isNaN; }; export type c4Return = ReturnType>; export type c4oReturn = ReturnType>; -export declare function d1(): () => (isNaN: typeof isNaN) => typeof isNaN; -export declare function d2(): () => (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; -export declare function d3(): () => (isNaN: number, bar: typeof isNaN) => typeof isNaN; -export declare function d4(): () => (isNaN: number) => typeof isNaN; +export declare function d1(): () => (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; +export declare function d2(): () => (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => typeof globalThis.isNaN; +export declare function d3(): () => (isNaN: number, bar: typeof globalThis.isNaN) => typeof globalThis.isNaN; +export declare function d4(): () => (isNaN: number) => typeof globalThis.isNaN; export type d4Return = ReturnType>>>; export declare class A { method1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; @@ -168,125 +168,3 @@ export declare class AsClassProperty { isNaN?: typeof globalThis.isNaN; } export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; - - -//// [DtsFileErrors] - - -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(1,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(2,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(6,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(7,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(11,35): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(12,36): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(13,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(14,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(18,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(19,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(23,35): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(24,36): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(30,8): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(31,8): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(36,36): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(37,38): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(38,38): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(41,35): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. - - -==== tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts (18 errors) ==== - export declare const a1: (isNaN: typeof isNaN) => typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - export declare const a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - export declare const a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; - export declare const a4: (isNaN: number) => typeof isNaN; - export declare const aObj: { - a1: (isNaN: typeof isNaN) => typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; - a4: (isNaN: number) => typeof isNaN; - }; - export type a4Return = ReturnType>; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. - export type a4oReturn = ReturnType>; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. - export declare const b1: (isNaN: typeof isNaN) => typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - export declare const b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - export declare const b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; - export declare const b4: (isNaN: number) => typeof isNaN; - export declare const bObj: { - b1: (isNaN: typeof isNaN) => typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN; - b4: (isNaN: number) => typeof isNaN; - }; - export type b4Return = ReturnType>; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. - export type b4oReturn = ReturnType>; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. - export declare function c1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; - export declare function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN; - export declare function c3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; - export declare function c4(isNaN: number): typeof globalThis.isNaN; - export declare const cObj: { - c1(isNaN: typeof isNaN): typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - c2(isNaN: typeof isNaN, bar?: typeof isNaN): typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - c3(isNaN: number, bar: typeof isNaN): typeof isNaN; - c4(isNaN: number): typeof isNaN; - }; - export type c4Return = ReturnType>; - export type c4oReturn = ReturnType>; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. - export declare function d1(): () => (isNaN: typeof isNaN) => typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - export declare function d2(): () => (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation. - export declare function d3(): () => (isNaN: number, bar: typeof isNaN) => typeof isNaN; - export declare function d4(): () => (isNaN: number) => typeof isNaN; - export type d4Return = ReturnType>>>; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'. - export declare class A { - method1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; - method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN; - method3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; - method4(isNaN: number): typeof globalThis.isNaN; - } - export declare function fromParameter(isNaN: number, bar: typeof globalThis.isNaN): () => { - bar: typeof globalThis.isNaN; - }; - export declare const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; - export declare function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; - export type AsObjectProperty = { - isNaN: typeof globalThis.isNaN; - }; - export declare class AsClassProperty { - isNaN?: typeof globalThis.isNaN; - } - export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; - \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitGlobalThisPreserved.types b/tests/baselines/reference/declarationEmitGlobalThisPreserved.types index ad13ce25fdf88..af48be340500e 100644 --- a/tests/baselines/reference/declarationEmitGlobalThisPreserved.types +++ b/tests/baselines/reference/declarationEmitGlobalThisPreserved.types @@ -464,7 +464,7 @@ export function fromParameter(isNaN: number, bar: typeof globalThis.isNaN) { // Non-inference cases. export const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN = (isNaN) => isNaN; ->explicitlyTypedVariable : (isNaN: (number: number) => boolean) => (number: number) => boolean +>explicitlyTypedVariable : (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN >isNaN : (number: number) => boolean >globalThis.isNaN : (number: number) => boolean >globalThis : typeof globalThis @@ -512,7 +512,7 @@ export class AsClassProperty { } export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; ->AsFunctionType : (isNaN: (number: number) => boolean) => (number: number) => boolean +>AsFunctionType : (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN >isNaN : (number: number) => boolean >globalThis.isNaN : (number: number) => boolean >globalThis : typeof globalThis diff --git a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types index 4e4bf5b76933a..5cc4e09d9ab6b 100644 --- a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types +++ b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types @@ -155,7 +155,7 @@ let p2 = p1.deeper({ two: '2' }) >p1.deeper({ two: '2' }) : { result: { one: string; } & { two: string; }; deeper: (child: U) => { result: { one: string; } & { two: string; } & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U & U; deeper: (child: U) => any; }; }; }; }; }; }; }; }; }; }; } >p1.deeper : (child: U) => { result: { one: string; } & U; deeper: (child: U) => { result: { one: string; } & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U & U & U & U; deeper: any; }; }; }; }; }; }; }; }; }; }; } >p1 : { result: { one: string; }; deeper: (child: U) => { result: { one: string; } & U; deeper: (child: U) => { result: { one: string; } & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U & U & U; deeper: (child: U) => any; }; }; }; }; }; }; }; }; }; }; } ->deeper : (child: U) => { result: { one: string; } & U; deeper: (child: U) => { result: { one: string; } & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U & U & U; deeper: (child: U) => any; }; }; }; }; }; }; }; }; }; } +>deeper : (child: U) => { result: { one: string; } & U; deeper: (child: U) => { result: { one: string; } & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & U & U & U & U & U & U & U & U & U & U & U; deeper: any; }; }; }; }; }; }; }; }; }; }; } >{ two: '2' } : { two: string; } >two : string >'2' : "2" @@ -181,7 +181,7 @@ let p3 = p2.deeper({ three: '3' }) >p2.deeper({ three: '3' }) : { result: { one: string; } & { two: string; } & { three: string; }; deeper: (child: U) => { result: { one: string; } & { two: string; } & { three: string; } & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & { three: string; } & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & { three: string; } & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & { three: string; } & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & { three: string; } & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & { three: string; } & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & { three: string; } & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & { three: string; } & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & { three: string; } & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & { three: string; } & U & U & U & U & U & U & U & U & U & U; deeper: (child: U) => any; }; }; }; }; }; }; }; }; }; }; } >p2.deeper : (child: U) => { result: { one: string; } & { two: string; } & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U & U & U; deeper: any; }; }; }; }; }; }; }; }; }; }; } >p2 : { result: { one: string; } & { two: string; }; deeper: (child: U) => { result: { one: string; } & { two: string; } & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U & U; deeper: (child: U) => any; }; }; }; }; }; }; }; }; }; }; } ->deeper : (child: U) => { result: { one: string; } & { two: string; } & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U & U; deeper: (child: U) => any; }; }; }; }; }; }; }; }; }; } +>deeper : (child: U) => { result: { one: string; } & { two: string; } & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U & U; deeper: (child: U) => { result: { one: string; } & { two: string; } & U & U & U & U & U & U & U & U & U & U & U; deeper: any; }; }; }; }; }; }; }; }; }; }; } >{ three: '3' } : { three: string; } >three : string >'3' : "3" diff --git a/tests/baselines/reference/genericTypeWithNonGenericBaseMisMatch.types b/tests/baselines/reference/genericTypeWithNonGenericBaseMisMatch.types index 247c692cc265f..928e2a6dfae36 100644 --- a/tests/baselines/reference/genericTypeWithNonGenericBaseMisMatch.types +++ b/tests/baselines/reference/genericTypeWithNonGenericBaseMisMatch.types @@ -1,7 +1,7 @@ === tests/cases/compiler/genericTypeWithNonGenericBaseMisMatch.ts === interface I { f: (a: { a: number }) => void ->f : (a: { a: number; }) => void +>f : (a: { a: number;}) => void >a : { a: number; } >a : number } diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.types b/tests/baselines/reference/parenthesizedContexualTyping2.types index 96f41e54af74b..ba37215a3d7c0 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping2.types +++ b/tests/baselines/reference/parenthesizedContexualTyping2.types @@ -6,7 +6,7 @@ // back if contextual typing is not taking effect. type FuncType = (x: (p: T) => T) => typeof x; ->FuncType : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => typeof x >x : (p: T) => T >p : T >x : (p: T) => T diff --git a/tests/baselines/reference/recursiveTypesWithTypeof.types b/tests/baselines/reference/recursiveTypesWithTypeof.types index 64a0ea35b5466..94e3f2fc78246 100644 --- a/tests/baselines/reference/recursiveTypesWithTypeof.types +++ b/tests/baselines/reference/recursiveTypesWithTypeof.types @@ -66,7 +66,7 @@ var h = h(); >h : () => any var i: (x: typeof i) => typeof x; ->i : (x: typeof i) => any +>i : (x: typeof i) => typeof x >x : (x: typeof i) => any >i : (x: any) => any >x : (x: any) => typeof x @@ -99,7 +99,7 @@ var h2 = new h2(); >h2 : new () => any var i2: new (x: typeof i2) => typeof x; ->i2 : new (x: typeof i2) => any +>i2 : new (x: typeof i2) => typeof x >x : new (x: typeof i2) => any >i2 : new (x: any) => any >x : new (x: any) => typeof x diff --git a/tests/baselines/reference/taggedTemplateContextualTyping1.types b/tests/baselines/reference/taggedTemplateContextualTyping1.types index 1d196fd5155e6..29b4d1ce3ca88 100644 --- a/tests/baselines/reference/taggedTemplateContextualTyping1.types +++ b/tests/baselines/reference/taggedTemplateContextualTyping1.types @@ -1,6 +1,6 @@ === tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts === type FuncType = (x: (p: T) => T) => typeof x; ->FuncType : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => typeof x >x : (p: T) => T >p : T >x : (p: T) => T diff --git a/tests/baselines/reference/taggedTemplateContextualTyping2.types b/tests/baselines/reference/taggedTemplateContextualTyping2.types index 46e4332e208b6..42fedd5f959d8 100644 --- a/tests/baselines/reference/taggedTemplateContextualTyping2.types +++ b/tests/baselines/reference/taggedTemplateContextualTyping2.types @@ -1,12 +1,12 @@ === tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping2.ts === type FuncType1 = (x: (p: T) => T) => typeof x; ->FuncType1 : (x: (p: T) => T) => (p: T) => T +>FuncType1 : (x: (p: T) => T) => typeof x >x : (p: T) => T >p : T >x : (p: T) => T type FuncType2 = (x: (p: T) => T) => typeof x; ->FuncType2 : (x: (p: T) => T) => (p: T) => T +>FuncType2 : (x: (p: T) => T) => typeof x >x : (p: T) => T >p : T >x : (p: T) => T diff --git a/tests/baselines/reference/targetTypeCastTest.types b/tests/baselines/reference/targetTypeCastTest.types index f4480c3040426..a15529f9fb6eb 100644 --- a/tests/baselines/reference/targetTypeCastTest.types +++ b/tests/baselines/reference/targetTypeCastTest.types @@ -1,6 +1,6 @@ === tests/cases/compiler/targetTypeCastTest.ts === declare var Point: { new(x:number, y:number): {x: number; y: number; }; } ->Point : new (x: number, y: number) => { x: number; y: number; } +>Point : new (x: number, y: number) => { x: number; y: number;} >x : number >y : number >x : number diff --git a/tests/baselines/reference/typeParametersInStaticMethods.types b/tests/baselines/reference/typeParametersInStaticMethods.types index aa6f3dedaae12..ae261c86386e1 100644 --- a/tests/baselines/reference/typeParametersInStaticMethods.types +++ b/tests/baselines/reference/typeParametersInStaticMethods.types @@ -3,8 +3,8 @@ class foo { >foo : foo static M(x: (x: T) => { x: { y: T } }) { ->M : (x: (x: T) => { x: { y: T;}; }) => void ->x : (x: T) => { x: { y: T;}; } +>M : (x: (x: T) => { x: { y: T; };}) => void +>x : (x: T) => { x: { y: T; };} >x : T >x : { y: T; } >y : T diff --git a/tests/baselines/reference/vardecl.types b/tests/baselines/reference/vardecl.types index 88cd1cd77cc4e..394befc5ef76e 100644 --- a/tests/baselines/reference/vardecl.types +++ b/tests/baselines/reference/vardecl.types @@ -121,7 +121,7 @@ var n4: { }[]; var d4: { ->d4 : { foo(n: string, x: { x: number; y: number; }): { x: number; y: number; }; } +>d4 : { foo(n: string, x: { x: number; y: number;}): { x: number; y: number;}; } foo(n: string, x: { x: number; y: number; }): { >foo : (n: string, x: { x: number; y: number;}) => { x: number; y: number;} From 27c0c921ba823af0987473f820b9a0df3a7ca8dc Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 17 Feb 2023 15:55:56 -0800 Subject: [PATCH 3/4] Simplify even more --- src/compiler/checker.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 19afee32933f1..58c4dd9f0519c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7312,7 +7312,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // It'd likely be better to store this somewhere else for isSymbolAccessible, but // since that API _only_ uses the enclosing declaration (and its parents), this is // seems like the best way to inject names into that search process. - const existingFakeScope = findAncestor(context.enclosingDeclaration, node => !!getNodeLinks(node).fakeScopeForSignatureDeclaration); + // + // Note that we only check the most immediate enclosingDeclaration; the only place we + // could potentially add another fake scope into the chain is right here, so we don't + // traverse all ancestors. + const existingFakeScope = getNodeLinks(context.enclosingDeclaration).fakeScopeForSignatureDeclaration ? context.enclosingDeclaration : undefined; Debug.assertOptionalNode(existingFakeScope, isBlock); const locals = existingFakeScope?.locals ?? createSymbolTable(); @@ -8074,7 +8078,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function getEnclosingDeclarationIgnoringFakeScope(enclosingDeclaration: Node) { - return findAncestor(enclosingDeclaration, n => !getNodeLinks(n).fakeScopeForSignatureDeclaration); + return getNodeLinks(enclosingDeclaration).fakeScopeForSignatureDeclaration ? enclosingDeclaration.parent : enclosingDeclaration; } /** From 142a817767717e920920fdeb8a21542851a7d70c Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 17 Feb 2023 16:25:57 -0800 Subject: [PATCH 4/4] Update comment --- src/compiler/checker.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 58c4dd9f0519c..307dcc7aee13b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7300,12 +7300,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { && !isInJSFile(signature.declaration) && some(expandedParams) ) { - // As a performance optimization, share the symbol table between all faked scopes - // in this node builder chain. This is especially needed when we are working on an - // excessively deep type; if we don't do this, then we spend all of our time adding - // more and more scopes that need to be searched in isSymbolAccessible later. Since - // all we really want to do is to mark certain names as unavailable, we can just - // keep all of the names we're introducing in one large table and push/pop from it as + // As a performance optimization, reuse the same fake scope within this chain. + // This is especially needed when we are working on an excessively deep type; + // if we don't do this, then we spend all of our time adding more and more + // scopes that need to be searched in isSymbolAccessible later. Since all we + // really want to do is to mark certain names as unavailable, we can just keep + // all of the names we're introducing in one large table and push/pop from it as // needed; isSymbolAccessible will walk upward and find the closest "fake" scope, // which will conveniently report on any and all faked scopes in the chain. //