ts-expect-error will report if there is no error.
Unused '@ts-expect-error' directive
Which can be solved with
// @ts-ignore
It’s a choice of course
which is why you should only use it on line that has error
normally // @ts-ignore is not desirable because it is not granular, it will just ignore everything and will ignore thing that you don't want to ignore (but is ok in this case)
and because of granularity // @ts-expect-error is very useful in type testing
True Sorry my mistake. Object keys is always a string.
object key can be numeric, it will be converted to string on runtime
type wise key type of both {[x:string]:unknown} and {[x:string | number ]:unknown} are string | number
which is why I said it is unnecessary, not incorrect
which is why you should only use it on line that has error
normally
// @ts-ignore
is not desirable because it is not granular, it will just ignore everything and will ignore thing that you don't want to ignore (but is ok in this case)and because of granularity
// @ts-expect-error
is very useful in type testingobject key can be numeric, it will be converted to string on runtime
type wise key type of both
{[x:string]:unknown}
and{[x:string | number ]:unknown}
arestring | number
which is why I said it is unnecessary, not incorrect
TS expect / ignore
The ideas which when to use, have you points to add? Or other advice?
a good analogy is something like const and let vs var
in what case you need var? almost none
so I never use ts ignore, I only use ts expect error
if you find yourself in need of ts ignore, you probably need refactoring or you have compatibility issue