Commit 3129f88
committed
fix(scanner): narrow
A class field like `readonly provider = 'threads' as const` emitted
`provider: unknown` in the generated .d.ts instead of `provider: 'threads'`.
`inferLiteralType`/`inferTypeFromDefault` never stripped the `as const`
suffix (so the string-literal check failed and fell through to `unknown`),
and instance `readonly` fields weren't treated as const-like, so `as const`
initializers were routed to the widening path.
`inferLiteralType` now strips `as const` before inferring, and the class
field path routes any `as const` initializer through it — so `as const`
narrows to the literal type regardless of modifiers (matching tsc). Adds a
regression test.as const class properties to their literal type1 parent 5f27f58 commit 3129f88
2 files changed
Lines changed: 29 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1560 | 1560 | | |
1561 | 1561 | | |
1562 | 1562 | | |
1563 | | - | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
1564 | 1568 | | |
1565 | 1569 | | |
1566 | 1570 | | |
| |||
2506 | 2510 | | |
2507 | 2511 | | |
2508 | 2512 | | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
2509 | 2517 | | |
2510 | | - | |
| 2518 | + | |
2511 | 2519 | | |
2512 | 2520 | | |
2513 | 2521 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1811 | 1811 | | |
1812 | 1812 | | |
1813 | 1813 | | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
1814 | 1833 | | |
1815 | 1834 | | |
1816 | 1835 | | |
| |||
0 commit comments