From f7f2e3d45dc83b4c57fdfa8a4fdbb8acdb5edb38 Mon Sep 17 00:00:00 2001 From: Amir Arad Date: Wed, 26 Jul 2017 09:46:20 +0300 Subject: [PATCH 1/2] add `NumberToString` conversion map useage: ```ts type MyType = ... NumberToString[I] ``` --- src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 63f48c7..762b737 100644 --- a/src/index.ts +++ b/src/index.ts @@ -173,7 +173,8 @@ export type NatToNumber = If< > > > - + +export type NumberToString = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']; // // strings // From 2f9451b3231c9e34d7ab7e44058d24a9f6fd6d65 Mon Sep 17 00:00:00 2001 From: amir-arad Date: Wed, 26 Jul 2017 10:43:36 +0300 Subject: [PATCH 2/2] fixed CI failure and added tests --- .gitignore | 1 + src/index.ts | 5 +++-- typings-checker/index.ts | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e1db05e..f869951 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules lib dev +/.idea/ diff --git a/src/index.ts b/src/index.ts index 762b737..5f0a547 100644 --- a/src/index.ts +++ b/src/index.ts @@ -151,6 +151,8 @@ export type Max = If, N2, N1> */ export type NumberToNat = TupleToObject<[_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10]> +export type NumberToString = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] + /** max Nat = _10 */ export type NatToNumber = If< NatEq, @@ -173,8 +175,7 @@ export type NatToNumber = If< > > > - -export type NumberToString = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']; + // // strings // diff --git a/typings-checker/index.ts b/typings-checker/index.ts index 96c3816..9cd6c51 100644 --- a/typings-checker/index.ts +++ b/typings-checker/index.ts @@ -92,3 +92,8 @@ const e4: E1 = { a: 'foo', b: true, c: 1 } type TTO = t.TupleToObject<[number, string]> const tto1: TTO = { 0: 1, 1: 'foo' } + +type FIVE = t.NumberToString[5] +const n2s1: FIVE = '5' +// $ExpectError Type '"6"' is not assignable to type '"5"' +const n2s2: FIVE = '6'