Skip to content
This repository was archived by the owner on Feb 16, 2021. It is now read-only.

Commit c9fa061

Browse files
committed
update to TypeScript 2.5
1 parent adfce07 commit c9fa061

File tree

3 files changed

+109
-22
lines changed

3 files changed

+109
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"prettier": "1.5.2",
2929
"tslint": "4.4.2",
3030
"tslint-config-standard": "4.0.0",
31-
"typescript": "2.4.1",
31+
"typescript": "^2.5.0-dev.20170808",
3232
"typings-checker": "1.1.2"
3333
},
3434
"tags": [],

src/index.ts

Lines changed: 100 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ export interface Nat {
6868
isZero: Bool
6969
}
7070

71-
export interface Positive {
72-
prev: Positive | _0
73-
isZero: 'false'
74-
}
75-
7671
export type _0 = { isZero: 'true' }
7772
export type _1 = Succ<_0>
7873
export type _2 = Succ<_1>
@@ -89,7 +84,7 @@ export type IsZero<N extends Nat> = N['isZero']
8984

9085
export type Succ<N extends Nat> = { prev: N; isZero: 'false' }
9186

92-
export type Prev<N extends Positive> = N['prev']
87+
export type Prev<N extends Nat> = N['prev']
9388

9489
export type NatEq<N1 extends Nat, N2 extends Nat> = {
9590
true: IsZero<N2>
@@ -213,6 +208,8 @@ export type PickExact<O, K extends keyof O> = Pick<O, K> & { [K1 in StringOmit<k
213208

214209
export type THNil = {
215210
IsHNil: 'true'
211+
head: never
212+
tail: never
216213
}
217214

218215
export type THCons<H, T extends THList> = {
@@ -225,9 +222,9 @@ export type THList = THNil | THCons<any, any>
225222

226223
export type THListIsTHNil<L extends THList> = L['IsHNil']
227224

228-
export type THListHead<L extends THCons<any, any>> = L['head']
225+
export type THListHead<L extends THList> = L['head']
229226

230-
export type THListTail<L extends THCons<any, any>> = L['tail']
227+
export type THListTail<L extends THList> = L['tail']
231228

232229
export type THListLength<L extends THList> = {
233230
true: _0
@@ -252,14 +249,14 @@ export type UnsafeTHListGet<L extends THList, I extends Nat> = {
252249
false: UnsafeTHListGet<THListTail<L>, Prev<I>>
253250
}[IsZero<I>]
254251

255-
export type THListReverse<L extends THList, Acc = THNil> = {
252+
export type THListReverse<L extends THList, Acc extends THList = THNil> = {
256253
true: Acc
257254
false: THListReverse<THListTail<L>, THCons<THListHead<L>, Acc>>
258255
}[THListIsTHNil<L>]
259256

260257
/** max length = 6 */
261258
export type THListToTuple<L extends THList> = {
262-
true: []
259+
true: never
263260
false: {
264261
true: [THListHead<L>]
265262
false: {
@@ -305,14 +302,96 @@ export type THListToTuple<L extends THList> = {
305302

306303
export type TupleToObject<T> = ObjectOmit<T, keyof Array<any>>
307304

308-
export type Increment = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
309-
310-
export type TupleLength<T, I = 0> = {
311-
true: TupleLength<T, Increment[I]>
312-
false: I
313-
}[ObjectHasKey<T, I>]
314-
315-
export type TupleToTHList<T, I = 0, L = THNil> = {
316-
true: TupleToTHList<T, Increment[I], THCons<T[I], L>>
317-
false: L
318-
}[ObjectHasKey<T, I>]
305+
export type TupleLength<T extends [any]> = {
306+
false: 0
307+
true: {
308+
false: 1
309+
true: {
310+
false: 2
311+
true: {
312+
false: 3
313+
true: {
314+
false: 4
315+
true: {
316+
false: 5
317+
true: {
318+
false: 6
319+
true: {
320+
false: 7
321+
true: {
322+
false: 8
323+
true: {
324+
false: 9
325+
true: 10
326+
}[ObjectHasKey<T, '9'>]
327+
}[ObjectHasKey<T, '8'>]
328+
}[ObjectHasKey<T, '7'>]
329+
}[ObjectHasKey<T, '5'>]
330+
}[ObjectHasKey<T, '5'>]
331+
}[ObjectHasKey<T, '4'>]
332+
}[ObjectHasKey<T, '3'>]
333+
}[ObjectHasKey<T, '2'>]
334+
}[ObjectHasKey<T, '1'>]
335+
}[ObjectHasKey<T, '0'>]
336+
337+
export type TupleToTHList<T extends [any]> = {
338+
false: THNil
339+
true: {
340+
false: THCons<T[0], THNil>
341+
true: {
342+
false: THCons<T[1], THCons<T[0], THNil>>
343+
true: {
344+
false: THCons<T[2], THCons<T[1], THCons<T[0], THNil>>>
345+
true: {
346+
false: THCons<T[3], THCons<T[2], THCons<T[1], THCons<T[0], THNil>>>>
347+
true: {
348+
false: THCons<T[4], THCons<T[3], THCons<T[2], THCons<T[1], THCons<T[0], THNil>>>>>
349+
true: {
350+
false: THCons<T[5], THCons<T[4], THCons<T[3], THCons<T[2], THCons<T[1], THCons<T[0], THNil>>>>>>
351+
true: {
352+
false: THCons<
353+
T[6],
354+
THCons<T[5], THCons<T[4], THCons<T[3], THCons<T[2], THCons<T[1], THCons<T[0], THNil>>>>>>
355+
>
356+
true: {
357+
false: THCons<
358+
T[7],
359+
THCons<
360+
T[6],
361+
THCons<T[5], THCons<T[4], THCons<T[3], THCons<T[2], THCons<T[1], THCons<T[0], THNil>>>>>>
362+
>
363+
>
364+
true: {
365+
false: THCons<
366+
T[8],
367+
THCons<
368+
T[7],
369+
THCons<
370+
T[6],
371+
THCons<T[5], THCons<T[4], THCons<T[3], THCons<T[2], THCons<T[1], THCons<T[0], THNil>>>>>>
372+
>
373+
>
374+
>
375+
true: THCons<
376+
T[9],
377+
THCons<
378+
T[8],
379+
THCons<
380+
T[7],
381+
THCons<
382+
T[6],
383+
THCons<T[5], THCons<T[4], THCons<T[3], THCons<T[2], THCons<T[1], THCons<T[0], THNil>>>>>>
384+
>
385+
>
386+
>
387+
>
388+
}[ObjectHasKey<T, '9'>]
389+
}[ObjectHasKey<T, '8'>]
390+
}[ObjectHasKey<T, '7'>]
391+
}[ObjectHasKey<T, '5'>]
392+
}[ObjectHasKey<T, '5'>]
393+
}[ObjectHasKey<T, '4'>]
394+
}[ObjectHasKey<T, '3'>]
395+
}[ObjectHasKey<T, '2'>]
396+
}[ObjectHasKey<T, '1'>]
397+
}[ObjectHasKey<T, '0'>]

typings-checker/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,11 @@ type FIVE = t.NumberToString[5]
9797
const n2s1: FIVE = '5'
9898
// $ExpectError Type '"6"' is not assignable to type '"5"'
9999
const n2s2: FIVE = '6'
100+
101+
const tl1: t.TupleLength<[number]> = 1
102+
const tl2: t.TupleLength<[number, string]> = 2
103+
const tl3: t.TupleLength<[number, string, boolean]> = 3
104+
105+
type T2THList1 = t.TupleToTHList<[number]>
106+
type T2THList2 = t.TupleToTHList<[number, string]>
107+
type T2THList3 = t.TupleToTHList<[number, string, boolean]>

0 commit comments

Comments
 (0)