Skip to content

Commit

Permalink
Look for usable type nodes in associated expressions for declaration …
Browse files Browse the repository at this point in the history
…emit (#57772)
  • Loading branch information
weswigham committed Mar 18, 2024
1 parent ac2e122 commit 66047f7
Show file tree
Hide file tree
Showing 191 changed files with 1,314 additions and 417 deletions.
199 changes: 160 additions & 39 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6517,7 +6517,7 @@ export function identifierIsThisKeyword(id: Identifier): boolean {
}

/** @internal */
export function getAllAccessorDeclarations(declarations: readonly Declaration[], accessor: AccessorDeclaration): AllAccessorDeclarations {
export function getAllAccessorDeclarations(declarations: readonly Declaration[] | undefined, accessor: AccessorDeclaration): AllAccessorDeclarations {
// TODO: GH#18217
let firstAccessor!: AccessorDeclaration;
let secondAccessor!: AccessorDeclaration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// from webpack/lib/Compilation.js and filed at #26427
/** @param {{ [s: string]: number }} map */
function mappy(map) {}
>mappy : (map: { [s: string]: number; }) => void
>mappy : (map: { [s: string]: number;}) => void
>map : { [s: string]: number; }

export class C {
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/anonterface.types
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module M {
>C : C

m(fn:{ (n:number):string; },n2:number):string {
>m : (fn: (n: number) => string, n2: number) => string
>m : (fn: { (n: number): string;}, n2: number) => string
>fn : (n: number) => string
>n : number
>n2 : number
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/arrayLiteralContextualType.types
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function foo(animals: IAnimal[]) { }
>animals : IAnimal[]

function bar(animals: { [n: number]: IAnimal }) { }
>bar : (animals: { [n: number]: IAnimal; }) => void
>bar : (animals: { [n: number]: IAnimal;}) => void
>animals : { [n: number]: IAnimal; }
>n : number

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ var a17: {

};
var a18: {
>a18 : { (x: { (a: number): number; (a: string): string; }): any[]; (x: { (a: boolean): boolean; (a: Date): Date; }): any[]; }
>a18 : { (x: { (a: number): number; (a: string): string;}): any[]; (x: { (a: boolean): boolean; (a: Date): Date;}): any[]; }

(x: {
>x : { (a: number): number; (a: string): string; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module Errors {
>b : number

var a16: {
>a16 : { (x: { (a: number): number; (a?: number): number; }): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean; }): boolean[]; }
>a16 : { (x: { (a: number): number; (a?: number): number;}): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean;}): boolean[]; }

(x: {
>x : { (a: number): number; (a?: number): number; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ var a17: {

};
var a18: {
>a18 : { new (x: { new (a: number): number; new (a: string): string; }): any[]; new (x: { new (a: boolean): boolean; new (a: Date): Date; }): any[]; }
>a18 : { new (x: { new (a: number): number; new (a: string): string;}): any[]; new (x: { new (a: boolean): boolean; new (a: Date): Date;}): any[]; }

new (x: {
>x : { new (a: number): number; new (a: string): string; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module Errors {
>b : number

var a16: {
>a16 : { new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }
>a16 : { new (x: { new (a: number): number; new (a?: number): number;}): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean;}): boolean[]; }

new (x: {
>x : { new (a: number): number; new (a?: number): number; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ h(async v => v ? (def) => { } : Promise.reject());

// repro from #29196
const increment: (
>increment : (num: number, str: string) => string | Promise<string | ((s: string) => any)>
>increment : (num: number, str: string) => Promise<((s: string) => any) | string> | string

num: number,
>num : number
Expand All @@ -130,7 +130,7 @@ const increment: (
}

const increment2: (
>increment2 : (num: number, str: string) => Promise<string | ((s: string) => any)>
>increment2 : (num: number, str: string) => Promise<((s: string) => any) | string>

num: number,
>num : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
declare namespace Windows.Foundation {
interface IPromise<TResult> {
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
>then : { <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => U_1) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => U_2) | undefined, error?: ((error: any) => IPromise<U_2>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>then : { <U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>; <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => U_1) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => U_2) | undefined, error?: ((error: any) => IPromise<U_2>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>success : ((value: TResult) => IPromise<U>) | undefined
>value : TResult
>error : ((error: any) => IPromise<U>) | undefined
Expand All @@ -13,7 +13,7 @@ declare namespace Windows.Foundation {
>progress : any

then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U_2>(success?: ((value: TResult) => U_2) | undefined, error?: ((error: any) => IPromise<U_2>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>; <U_2>(success?: ((value: TResult) => U_2) | undefined, error?: ((error: any) => IPromise<U_2>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>success : ((value: TResult) => IPromise<U>) | undefined
>value : TResult
>error : ((error: any) => U) | undefined
Expand All @@ -22,7 +22,7 @@ declare namespace Windows.Foundation {
>progress : any

then<U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => IPromise<U_2>) | undefined, error?: ((error: any) => U_2) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => IPromise<U_2>) | undefined, error?: ((error: any) => U_2) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => U_3) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; }
>success : ((value: TResult) => U) | undefined
>value : TResult
>error : ((error: any) => IPromise<U>) | undefined
Expand All @@ -31,7 +31,7 @@ declare namespace Windows.Foundation {
>progress : any

then<U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => IPromise<U_2>) | undefined, error?: ((error: any) => U_2) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => IPromise<U_3>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; }
>then : { <U_1>(success?: ((value: TResult) => IPromise<U_1>) | undefined, error?: ((error: any) => IPromise<U_1>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_1>; <U_2>(success?: ((value: TResult) => IPromise<U_2>) | undefined, error?: ((error: any) => U_2) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_2>; <U_3>(success?: ((value: TResult) => U_3) | undefined, error?: ((error: any) => IPromise<U_3>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U_3>; <U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>; }
>success : ((value: TResult) => U) | undefined
>value : TResult
>error : ((error: any) => U) | undefined
Expand All @@ -40,7 +40,7 @@ declare namespace Windows.Foundation {
>progress : any

done<U>(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void;
>done : <U>(success?: ((value: TResult) => any) | undefined, error?: ((error: any) => any) | undefined, progress?: ((progress: any) => void) | undefined) => void
>done : <U>(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void) => void
>success : ((value: TResult) => any) | undefined
>value : TResult
>error : ((error: any) => any) | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare const foo: ["a", string, number] | ["b", string, boolean];
>foo : ["a", string, number] | ["b", string, boolean]

export function test(arg: { index?: number }) {
>test : (arg: { index?: number | undefined; }) => void
>test : (arg: { index?: number;}) => void
>arg : { index?: number | undefined; }
>index : number | undefined

Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/awaitedTypeStrictNull.types
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ interface Obj { x: number }
>x : number

async function fn<T>(): Promise<T extends object ? { [K in keyof T]: Obj } : Obj> {
>fn : <T>() => Promise<T extends object ? { [K in keyof T]: Obj; } : Obj>
>fn : <T>() => Promise<T extends object ? { [K in keyof T]: Obj;} : Obj>

// Per #45924, this was failing due to incorrect inference both above and here.
// Should not error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ interface A { // T

};
a18: {
>a18 : { (x: { (a: number): number; (a: string): string; }): any[]; (x: { (a: boolean): boolean; (a: Date): Date; }): any[]; }
>a18 : { (x: { (a: number): number; (a: string): string;}): any[]; (x: { (a: boolean): boolean; (a: Date): Date;}): any[]; }

(x: {
>x : { (a: number): number; (a: string): string; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module Errors {
>b : number

a16: {
>a16 : { (x: { (a: number): number; (a?: number): number; }): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean; }): boolean[]; }
>a16 : { (x: { (a: number): number; (a?: number): number;}): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean;}): boolean[]; }

// type of parameter is overload set which means we can't do inference based on this type
(x: {
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/callsOnComplexSignatures.types
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ function test2() {

interface Messages {
readonly foo: (options: { [key: string]: any, b: number }) => string;
>foo : (options: { [key: string]: any; b: number; }) => string
>foo : (options: { [key: string]: any; b: number;}) => string
>options : { [key: string]: any; b: number; }
>key : string
>b : number

readonly bar: (options: { [key: string]: any, a: string }) => string;
>bar : (options: { [key: string]: any; a: string; }) => string
>bar : (options: { [key: string]: any; a: string;}) => string
>options : { [key: string]: any; a: string; }
>key : string
>a : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ let a;
>a : any

function foo3(y = { x: <typeof z>a }, z = 1) {
>foo3 : (y?: { x: number; }, z?: number) => void
>y : { x: number; }
>{ x: <typeof z>a } : { x: number; }
>foo3 : (y?: { x: typeof z; }, z?: number) => void
>y : { x: typeof z; }
>{ x: <typeof z>a } : { x: typeof z; }
>x : number
><typeof z>a : number
>z : number
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/coAndContraVariantInferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface Action<TName extends string, TPayload> {
name: TName;
payload: TPayload;
}
declare const actionA: Action<"ACTION_A", string>;
declare const actionB: Action<"ACTION_B", boolean>;
declare const actionA: Action<'ACTION_A', string>;
declare const actionB: Action<'ACTION_B', boolean>;
declare function call<TName extends string, TPayload>(action: Action<TName, TPayload>, fn: (action: Action<TName, TPayload>) => any): void;
declare const printFn: (action: typeof actionA | typeof actionB) => void;
4 changes: 2 additions & 2 deletions tests/baselines/reference/collisionArgumentsInType.types
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var v12: (arguments: number, ...restParameters) => void; // no error - no code g
>restParameters : any[]

var v2: {
>v2 : { (arguments: number, ...restParameters: any[]): any; new (arguments: number, ...restParameters: any[]): any; foo(arguments: number, ...restParameters: any[]): any; prop: (arguments: number, ...restParameters: any[]) => void; }
>v2 : { (arguments: number, ...restParameters: any[]): any; new (arguments: number, ...restParameters: any[]): any; foo(arguments: number, ...restParameters: any[]): any; prop: (arguments: number, ...restParameters: any) => void; }

(arguments: number, ...restParameters); // no error - no code gen
>arguments : number
Expand All @@ -33,7 +33,7 @@ var v2: {
>restParameters : any[]
}
var v21: {
>v21 : { (i: number, ...arguments: any[]): any; new (i: number, ...arguments: any[]): any; foo(i: number, ...arguments: any[]): any; prop: (i: number, ...arguments: any[]) => void; }
>v21 : { (i: number, ...arguments: any[]): any; new (i: number, ...arguments: any[]): any; foo(i: number, ...arguments: any[]): any; prop: (i: number, ...arguments: any) => void; }

(i: number, ...arguments); // no error - no code gen
>i : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var v1: (_i: number, ...restParameters) => void; // no error - no code gen
>restParameters : any[]

var v2: {
>v2 : { (_i: number, ...restParameters: any[]): any; new (_i: number, ...restParameters: any[]): any; foo(_i: number, ...restParameters: any[]): any; prop: (_i: number, ...restParameters: any[]) => void; }
>v2 : { (_i: number, ...restParameters: any[]): any; new (_i: number, ...restParameters: any[]): any; foo(_i: number, ...restParameters: any[]): any; prop: (_i: number, ...restParameters: any) => void; }

(_i: number, ...restParameters); // no error - no code gen
>_i : number
Expand Down
Loading

0 comments on commit 66047f7

Please sign in to comment.