mattpocock / ts-error-translator

VSCode extension to turn TypeScript errors into plain English
https://ts-error-translator.vercel.app
2.36k stars 90 forks source link

Translation request for 2411 #241

Open vrsttl opened 9 months ago

vrsttl commented 9 months ago

Error Text

Property 'isBlurred' of type 'boolean' is not assignable to 'string' index type 'number'.

Supporting Information

Please provide other information which led to this error, and any specific questions you have about it:

I have this type:

export type OperatingModeData = {
    [key: string]: number;
    maxCapacity: number;
    maxPower: number;
};

A requirement came in to extend this with an isBlurred: boolean field. I figured out that I the type signature doesn't allow for the following:

export type OperatingModeData = {
    [key: string]: number;
    maxCapacity: number;
    maxPower: number;
    isBlurred: boolean;
};

so I just went with isBlurred: 0 | 1 and when using it, I cast Number(isBlurred). While it works, on CR I was asked why I chose this solution and had to explain that I couldn't make this work with type intersections either, because the type checker was complaining.

Solving this is another question, but I think a good clarification in the error translator would be very useful to start the process with.