Closed
Description
Bug Report
π Search Terms
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about it
β― Playground Link
Playground link with relevant code
π» Code
const fontSizes = {
h1: 50,
h2: 45,
h3: 40,
h4: 35,
h5: 30,
h6: 25,
}
type Props = {
level: 1 | 2 | 3 | 4 | 5 | 6;
}
const getFontSizeForHeader = ({ level }: Props) => fontSizes[`h${level}`]; // error
console.log('Test', getFontSizeForHeader({ level: 1 }));
π Actual behavior
When indexing an object with a template string, the template string is typed just as string
instead of the proper union, causing an error and requiring a type cast or ts-ignore to rid.
π Expected behavior
The template string typing to be used to check for valid indexing