aboutsummaryrefslogtreecommitdiff
path: root/examples/guess-number.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-11 16:02:26 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-11 16:02:26 +0530
commit49d6379c3d40b684b28f4a957ff1ffb81a2560ee (patch)
treefac62b2de1670ecfea6496949b028fa8fe0fe444 /examples/guess-number.ts
parenta6ff70d09e1e5f161e401a3665bfe44b2abfc44e (diff)
downloadts-types-lang-49d6379c3d40b684b28f4a957ff1ffb81a2560ee.tar.gz
ts-types-lang-49d6379c3d40b684b28f4a957ff1ffb81a2560ee.zip
refactor: minor refactor all around
Diffstat (limited to '')
-rw-r--r--examples/guess-number.ts6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/guess-number.ts b/examples/guess-number.ts
index 169805f..45d60e6 100644
--- a/examples/guess-number.ts
+++ b/examples/guess-number.ts
@@ -7,15 +7,15 @@ export type main = [
Bind<JsExpr<'Math.floor(Math.random() * 10)'>, StartGuessing>
]
+type Len<Ls extends any[]> = Ls['length'] extends number ? Ls['length'] : 0
+
interface AskForGuess<N extends number, Attempts extends 0[]> extends Kind1<string> {
return: `${this['input']}` extends `${N}`
? PutStringLn<'Yay! You got it right!'>
: Do<
[
PutString<'Wrong guess. Total attempts'>,
- PutStringLn<` ${[...Attempts, 0] extends infer Ls extends 0[]
- ? Ls['length']
- : 0}/5`>,
+ PutStringLn<` ${Len<[...Attempts, 0]>}/5`>,
(StartGuessing<[...Attempts, 0]> & { input: N })['return']
]
>