Closed
Description
Bug Report
π Search Terms
template literal string pattern
π Version & Regression Information
- Typescript 4.4.3
- Typescript 4.4.5-beta
β― Playground Link
Playground link with relevant code
π» Code
interface IDocument {
name: string;
[added_: `added_${string}`]: number[] | undefined;
}
const tech1 = {
uuid: '70b26275-5096-4e4b-9d50-3c965c9e5073',
};
// why does this error?
const doc: IDocument = {
name: "",
[`added_${tech1.uuid}`]: [19700101],
};
// but this doesn't?
const doc2: IDocument = {
name: "",
[`added_abc`]: [12345]
}
interface IDocument2 {
[added_: `added_${string}`]: number[] | undefined;
}
// and this doesn't?
const doc3: IDocument2 = {
[`added_${tech1.uuid}`]: [19700101],
}
π Actual behavior
Type '{ [x: string]: string | number[]; name: string; }' is not assignable to type 'IDocument'.
'string' and '`added_${string}`' index signatures are incompatible.
Type 'string | number[]' is not assignable to type 'number[] | undefined'.
Type 'string' is not assignable to type 'number[] | undefined'.
π Expected behavior
I don't understand why there is an error. If i remove the "name" key, the error goes away.
If i replace the templated string with a literal string added_abc
the error goes away