Skip to content

Commit 28aece0

Browse files
tests: reduce/map WIP
1 parent 9bbae94 commit 28aece0

File tree

4 files changed

+530
-224
lines changed

4 files changed

+530
-224
lines changed

tests/baselines/reference/typeCall.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,39 @@ type regexpIsPrimitive3 = genericIsPrimitive3(RegExp)
4343

4444
type map = <Fn extends (v: T) => any, O extends { [k: string]: T }, T>(fn: Fn, obj: O) => { [P in keyof O]: Fn(O[P]) };
4545
type z = map(<T>(v: T) => [T], { a: 1, b: 2, c: 3 });
46+
declare function map<Fn extends (v: T) => any, O extends { [k: string]: T }, T>(fn: Fn, obj: O): map(Fn, O);
47+
// let z = map(<T>(v: T) => [T], { a: 1, b: 2, c: 3 });
48+
// // fails with error: Cannot read property 'parent' of undefined at createDiagnosticForNodeFromMessageChain
49+
50+
type Inc = { [k: string]: string; 0:'1', 1:'2', 2:'3', 3:'4', 4:'5', 5:'6', 6:'7', 7:'8', 8:'9' };
51+
type StringToNumber = { [k: string]: number; 0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8};
52+
type TupleHasIndex<Arr extends any[], I extends string> = ({[K in keyof Arr]: '1' } & { [k: string]: '0' })[I];
53+
type PathFn<T extends { [k: string]: any }, R extends Array<string>, I extends string = '0'> =
54+
{ 1: PathFn<T[R[StringToNumber[I]]], R, Inc[I]>, 0: T }[TupleHasIndex<R, I>];
55+
type PathTest = PathFn<{ a: { b: ['c', { d: 'e' }] } }, ['a', 'b', '1', 'd']>;
56+
declare function path<T extends { [k: string]: any }, R extends Array<string>>(obj: T, path: R): PathFn<T, R>;
57+
const obj = null! as { a: { b: ['c', { d: 'e' }] } };
58+
const keys = null! as ['a', 'b', '1', 'd'];
59+
const pathTest = path(obj, keys);
60+
// "e"
61+
62+
// type Reduce<
63+
// Fn extends (previousValue: T, currentValue: R[number], currentIndex?: number, array?: R) => any,
64+
// T,
65+
// R extends any[],
66+
// I extends string = '0'
67+
// > = { 1: Reduce<Fn(T, R[StringToNumber[I]], I, R), R, Inc[I]>, 0: T }[TupleHasIndex<R, I>];
68+
// // fails with error: Cannot read property 'kind' of undefined at resolveCall
69+
// declare function reduce<
70+
// Fn extends (previousValue: any, currentValue: R[number], currentIndex?: number, array?: R) => any,
71+
// R extends any[],
72+
// U,
73+
// I extends string = '0'
74+
// >(callbackfn: Fn, initialValue: U, array: R): Reduce<Fn, U, R>;
75+
// declare function path2<T extends { [k: string]: any }, R extends Array<string>>(obj: T, path: R):
76+
// Reduce<<Prev, Curr>(previousValue: Prev, currentValue: Curr, currentIndex?: number, array?: any[]) => Prev[Curr], T, R>;
77+
// const pathTest2 = path2(obj, keys);
78+
// // "e"
4679

4780
// binary function composition
4881
type Fn1 = <T1 extends number>(v1: T1[]) => { [k: string]: T1 };
@@ -172,6 +205,9 @@ function comparability<T>(x: T, y: () => T) {
172205

173206
//// [typeCall.js]
174207
var a = 'foo';
208+
var obj = null;
209+
var keys = null;
210+
var pathTest = path(obj, keys);
175211
var fn1 = null;
176212
var fn2 = null;
177213
// type Fn4 = Fn3(1); // errors, ok

0 commit comments

Comments
 (0)