stc
stc copied to clipboard
`extends` should handle `string` and a template literal type
Problem
This is a follow-up of https://github.com/dudykr/stc/pull/212
warning: Type
--> $DIR/tests/visualize/types/literal/templateLiteralTypes2.ts:96:12
|
96 | const t4 = takesLiteral(id4); // unknown
| ^^^^^^^^^^^^^^^^^
|
= note: string extends `foo.bar.${infer R}` ? {
} : unknown
It should be unknown
instead of being a conditional type
warning: Type
--> $DIR/tests/visualize/types/literal/templateLiteralTypes2.ts:90:12
|
90 | const t2 = takesLiteral(id2); // "baz"
| ^^^^^^^^^^^^^^^^^
|
= note: "foo.bar.baz" extends foo.bar.${infer R}
? {
} : unknown
It should be "baz"
(R
) instead.
Solution
We should add a special case for child = string
and parent = template literal type to https://github.com/dudykr/stc/blob/269f6c07676f728e667ca5fb4c80d7f17f66a98d/crates/stc_ts_file_analyzer/src/analyzer/generic/expander.rs#L125-L136
I'm working on this.
@AcrylicShrimp Are you still working on this?
@kdy1 Yes I am!
@AcrylicShrimp Are you still working on it?
@kdy1 Sorry for late, I'll upload PR on this weekend! Thank you.
I'll take on this