Bug Report
🔎 Search Terms
template literal, string interpolation, type narrowing
🕗 Version & Regression Information
- I was unable to test this on prior versions prior to 4.1 because template literal types were only added then
⏯ Playground Link
I have a hard time describing this issue, the playground link will explain it better I think:
Playground Link
I would expect fn2 to work in the same way that fn1 does
💻 Code
type A = {
type: "atype";
acontent: string;
}
type B = {
type: "btype";
bcontent: string
}
function fn1(val: A|B) {
if(val.type === "atype") {
console.log(val.acontent);
}
if(val.type === "btype") {
console.log(val.bcontent);
}
}
type Modified<T extends A|B> =
Omit<T, "type"> & {
type: `prefix-${T["type"]}`;
};
function fn2(val: Modified<A|B>) {
if(val.type === "prefix-atype") {
console.log(val.acontent);
}
if(val.type === "prefix-btype") {
console.log(val.bcontent);
}
}
🙁 Actual behavior
Errors in the console.logs in fn2
🙂 Expected behavior
No errors, same as in fn1.
Bug Report
🔎 Search Terms
template literal, string interpolation, type narrowing
🕗 Version & Regression Information
⏯ Playground Link
I have a hard time describing this issue, the playground link will explain it better I think:
Playground Link
I would expect
fn2to work in the same way thatfn1does💻 Code
🙁 Actual behavior
Errors in the
console.logs infn2🙂 Expected behavior
No errors, same as in
fn1.