kaleidawave / ezno

A fast and correct TypeScript type checker and compiler with additional experiments
https://kaleidawave.github.io/posts/introducing-ezno/
MIT License
2.55k stars 47 forks source link

Number-embedded template literal doesn't validate collect #217

Closed sor4chi closed 6 days ago

sor4chi commented 1 week ago

TSC

in:

const invalidNum: `${1}` = 1;
const invalidNum2: `${1}` = "1";
const invalidNum3: `${1}` = "2";

out:

tmp.ts:1:7 - error TS2322: Type '1' is not assignable to type '"1"'.

1 const invalidNum: `${1}` = 1;
        ~~~~~~~~~~

tmp.ts:3:7 - error TS2322: Type '"2"' is not assignable to type '"1"'.

3 const invalidNum3: `${1}` = "2";
        ~~~~~~~~~~~

Ezno

in:

error: 
  ┌─ tmp.ts:2:29
  │
2 │ const invalidNum2: `${1}` = "1";
  │                    -----    ^^^ Type "1" is not assignable to type string
  │                    │         
  │                    Variable declared with type string

error: 
  ┌─ tmp.ts:3:29
  │
3 │ const invalidNum3: `${1}` = "2";
  │                    -----    ^^^ Type "2" is not assignable to type string
  │                    │         
  │                    Variable declared with type string
kaleidawave commented 1 week ago

Hmm, that is strange. I know that the string literal types are encoded by additions. So `A ${T}` = "A" + T. Maybe 1 + 0 = 1 so that is why it passes. Will investigate in #209

kaleidawave commented 6 days ago

Fixed in #209

https://github.com/kaleidawave/ezno/pull/209/files#diff-2d4b5f2bbb18c63488b819989dcb27e036a026c6e13e4ec60362b7f78de98dedR3783-R3792