Skip to content

Commit 3aa05b2

Browse files
committed
Accept new baselines
1 parent b4836e3 commit 3aa05b2

File tree

5 files changed

+971
-172
lines changed

5 files changed

+971
-172
lines changed

tests/baselines/reference/keyofAndIndexedAccess.js

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,36 @@ function f60<T>(source: T, target: T) {
219219
}
220220
}
221221

222+
function f70(func: <T, U>(k1: keyof (T | U), k2: keyof (T & U)) => void) {
223+
func<{ a: any, b: any }, { a: any, c: any }>('a', 'a');
224+
func<{ a: any, b: any }, { a: any, c: any }>('a', 'b');
225+
func<{ a: any, b: any }, { a: any, c: any }>('a', 'c');
226+
}
227+
228+
function f71(func: <T, U>(x: T, y: U) => Partial<T & U>) {
229+
let x = func({ a: 1, b: "hello" }, { c: true });
230+
x.a; // number | undefined
231+
x.b; // string | undefined
232+
x.c; // boolean | undefined
233+
}
234+
235+
function f72(func: <T, U, K extends keyof T | keyof U>(x: T, y: U, k: K) => (T & U)[K]) {
236+
let a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number
237+
let b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string
238+
let c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean
239+
}
240+
241+
function f73(func: <T, U, K extends keyof (T & U)>(x: T, y: U, k: K) => (T & U)[K]) {
242+
let a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number
243+
let b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string
244+
let c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean
245+
}
246+
247+
function f74(func: <T, U, K extends keyof (T | U)>(x: T, y: U, k: K) => (T | U)[K]) {
248+
let a = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'a'); // number
249+
let b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean
250+
}
251+
222252
// Repros from #12011
223253

224254
class Base {
@@ -291,7 +321,39 @@ var empty = one(() => {}) // inferred as {}, expected
291321
type Handlers<T> = { [K in keyof T]: (t: T[K]) => void }
292322
declare function on<T>(handlerHash: Handlers<T>): T
293323
var hashOfEmpty1 = on({ test: () => {} }); // {}
294-
var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean }
324+
var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean }
325+
326+
// Repro from #12624
327+
328+
interface Options1<Data, Computed> {
329+
data?: Data
330+
computed?: Computed;
331+
}
332+
333+
declare class Component1<Data, Computed> {
334+
constructor(options: Options1<Data, Computed>);
335+
get<K extends keyof (Data & Computed)>(key: K): (Data & Computed)[K];
336+
}
337+
338+
let c1 = new Component1({
339+
data: {
340+
hello: ""
341+
}
342+
});
343+
344+
c1.get("hello");
345+
346+
// Repro from #12625
347+
348+
interface Options2<Data, Computed> {
349+
data?: Data
350+
computed?: Computed;
351+
}
352+
353+
declare class Component2<Data, Computed> {
354+
constructor(options: Options2<Data, Computed>);
355+
get<K extends keyof Data | keyof Computed>(key: K): (Data & Computed)[K];
356+
}
295357

296358
//// [keyofAndIndexedAccess.js]
297359
var __extends = (this && this.__extends) || function (d, b) {
@@ -438,6 +500,31 @@ function f60(source, target) {
438500
target[k] = source[k];
439501
}
440502
}
503+
function f70(func) {
504+
func('a', 'a');
505+
func('a', 'b');
506+
func('a', 'c');
507+
}
508+
function f71(func) {
509+
var x = func({ a: 1, b: "hello" }, { c: true });
510+
x.a; // number | undefined
511+
x.b; // string | undefined
512+
x.c; // boolean | undefined
513+
}
514+
function f72(func) {
515+
var a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number
516+
var b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string
517+
var c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean
518+
}
519+
function f73(func) {
520+
var a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number
521+
var b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string
522+
var c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean
523+
}
524+
function f74(func) {
525+
var a = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'a'); // number
526+
var b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean
527+
}
441528
// Repros from #12011
442529
var Base = (function () {
443530
function Base() {
@@ -496,6 +583,12 @@ var assignTo2 = function (object, key1, key2) {
496583
var empty = one(function () { }); // inferred as {}, expected
497584
var hashOfEmpty1 = on({ test: function () { } }); // {}
498585
var hashOfEmpty2 = on({ test: function (x) { } }); // { test: boolean }
586+
var c1 = new Component1({
587+
data: {
588+
hello: ""
589+
}
590+
});
591+
c1.get("hello");
499592

500593

501594
//// [keyofAndIndexedAccess.d.ts]
@@ -603,6 +696,11 @@ declare function f53<T, K extends keyof T>(obj: {
603696
declare function f54<T>(obj: T, key: keyof T): void;
604697
declare function f55<T, K extends keyof T>(obj: T, key: K): void;
605698
declare function f60<T>(source: T, target: T): void;
699+
declare function f70(func: <T, U>(k1: keyof (T | U), k2: keyof (T & U)) => void): void;
700+
declare function f71(func: <T, U>(x: T, y: U) => Partial<T & U>): void;
701+
declare function f72(func: <T, U, K extends keyof T | keyof U>(x: T, y: U, k: K) => (T & U)[K]): void;
702+
declare function f73(func: <T, U, K extends keyof (T & U)>(x: T, y: U, k: K) => (T & U)[K]): void;
703+
declare function f74(func: <T, U, K extends keyof (T | U)>(x: T, y: U, k: K) => (T | U)[K]): void;
606704
declare class Base {
607705
get<K extends keyof this>(prop: K): this[K];
608706
set<K extends keyof this>(prop: K, value: this[K]): void;
@@ -640,3 +738,22 @@ declare var hashOfEmpty1: {};
640738
declare var hashOfEmpty2: {
641739
test: boolean;
642740
};
741+
interface Options1<Data, Computed> {
742+
data?: Data;
743+
computed?: Computed;
744+
}
745+
declare class Component1<Data, Computed> {
746+
constructor(options: Options1<Data, Computed>);
747+
get<K extends keyof (Data & Computed)>(key: K): (Data & Computed)[K];
748+
}
749+
declare let c1: Component1<{
750+
hello: string;
751+
}, {}>;
752+
interface Options2<Data, Computed> {
753+
data?: Data;
754+
computed?: Computed;
755+
}
756+
declare class Component2<Data, Computed> {
757+
constructor(options: Options2<Data, Computed>);
758+
get<K extends keyof Data | keyof Computed>(key: K): (Data & Computed)[K];
759+
}

0 commit comments

Comments
 (0)