Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Feb 4, 2023
1 parent 6a261ad commit 7c22dcb
Showing 3 changed files with 143 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/baselines/reference/contextualTypeCaching.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
=== tests/cases/compiler/contextualTypeCaching.ts ===
// Repro from #52575

export interface Event<T> {
>Event : Symbol(Event, Decl(contextualTypeCaching.ts, 0, 0))
>T : Symbol(T, Decl(contextualTypeCaching.ts, 2, 23))

callback: (response: T) => void;
>callback : Symbol(Event.callback, Decl(contextualTypeCaching.ts, 2, 27))
>response : Symbol(response, Decl(contextualTypeCaching.ts, 3, 15))
>T : Symbol(T, Decl(contextualTypeCaching.ts, 2, 23))

nested: {
>nested : Symbol(Event.nested, Decl(contextualTypeCaching.ts, 3, 36))

nestedCallback: (response: T) => void;
>nestedCallback : Symbol(nestedCallback, Decl(contextualTypeCaching.ts, 4, 13))
>response : Symbol(response, Decl(contextualTypeCaching.ts, 5, 25))
>T : Symbol(T, Decl(contextualTypeCaching.ts, 2, 23))
}
}

export type CustomEvents = {
>CustomEvents : Symbol(CustomEvents, Decl(contextualTypeCaching.ts, 7, 1))

a: Event<string>
>a : Symbol(a, Decl(contextualTypeCaching.ts, 9, 28))
>Event : Symbol(Event, Decl(contextualTypeCaching.ts, 0, 0))

b: Event<number>
>b : Symbol(b, Decl(contextualTypeCaching.ts, 10, 20))
>Event : Symbol(Event, Decl(contextualTypeCaching.ts, 0, 0))

};

declare function emit<T extends keyof CustomEvents>(type: T, data: CustomEvents[T]): void
>emit : Symbol(emit, Decl(contextualTypeCaching.ts, 12, 2))
>T : Symbol(T, Decl(contextualTypeCaching.ts, 14, 22))
>CustomEvents : Symbol(CustomEvents, Decl(contextualTypeCaching.ts, 7, 1))
>type : Symbol(type, Decl(contextualTypeCaching.ts, 14, 52))
>T : Symbol(T, Decl(contextualTypeCaching.ts, 14, 22))
>data : Symbol(data, Decl(contextualTypeCaching.ts, 14, 60))
>CustomEvents : Symbol(CustomEvents, Decl(contextualTypeCaching.ts, 7, 1))
>T : Symbol(T, Decl(contextualTypeCaching.ts, 14, 22))

emit('a', {
>emit : Symbol(emit, Decl(contextualTypeCaching.ts, 12, 2))

callback: (r) => {},
>callback : Symbol(callback, Decl(contextualTypeCaching.ts, 16, 11))
>r : Symbol(r, Decl(contextualTypeCaching.ts, 17, 15))

nested: {
>nested : Symbol(nested, Decl(contextualTypeCaching.ts, 17, 24))

nestedCallback: (r) => {},
>nestedCallback : Symbol(nestedCallback, Decl(contextualTypeCaching.ts, 18, 13))
>r : Symbol(r, Decl(contextualTypeCaching.ts, 19, 25))

},
});

56 changes: 56 additions & 0 deletions tests/baselines/reference/contextualTypeCaching.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
=== tests/cases/compiler/contextualTypeCaching.ts ===
// Repro from #52575

export interface Event<T> {
callback: (response: T) => void;
>callback : (response: T) => void
>response : T

nested: {
>nested : { nestedCallback: (response: T) => void; }

nestedCallback: (response: T) => void;
>nestedCallback : (response: T) => void
>response : T
}
}

export type CustomEvents = {
>CustomEvents : { a: Event<string>; b: Event<number>; }

a: Event<string>
>a : Event<string>

b: Event<number>
>b : Event<number>

};

declare function emit<T extends keyof CustomEvents>(type: T, data: CustomEvents[T]): void
>emit : <T extends keyof CustomEvents>(type: T, data: CustomEvents[T]) => void
>type : T
>data : CustomEvents[T]

emit('a', {
>emit('a', { callback: (r) => {}, nested: { nestedCallback: (r) => {}, },}) : void
>emit : <T extends keyof CustomEvents>(type: T, data: CustomEvents[T]) => void
>'a' : "a"
>{ callback: (r) => {}, nested: { nestedCallback: (r) => {}, },} : { callback: (r: string) => void; nested: { nestedCallback: (r: string) => void; }; }

callback: (r) => {},
>callback : (r: string) => void
>(r) => {} : (r: string) => void
>r : string

nested: {
>nested : { nestedCallback: (r: string) => void; }
>{ nestedCallback: (r) => {}, } : { nestedCallback: (r: string) => void; }

nestedCallback: (r) => {},
>nestedCallback : (r: string) => void
>(r) => {} : (r: string) => void
>r : string

},
});

25 changes: 25 additions & 0 deletions tests/cases/compiler/contextualTypeCaching.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @strict: true
// @noEmit: true

// Repro from #52575

export interface Event<T> {
callback: (response: T) => void;
nested: {
nestedCallback: (response: T) => void;
}
}

export type CustomEvents = {
a: Event<string>
b: Event<number>
};

declare function emit<T extends keyof CustomEvents>(type: T, data: CustomEvents[T]): void

emit('a', {
callback: (r) => {},
nested: {
nestedCallback: (r) => {},
},
});

0 comments on commit 7c22dcb

Please sign in to comment.