Often TS fails for me because the type it infers is different from what I expect it to be. I could force typecast variables, but I'd prefer to figure out why TS isn't inferring the types correctly.
Is there a way to print the type that TS believes a variable is?
E.g.:
const obj = [
{ a: 'foo' },
{ b: 'bar' },
];
printTsType(obj[0].a);
I would expect this to be the literal 'foo', but I think TS just infers string.
obj[0].ato be'foo'by using{a: 'foo' as const}orconst obj = [...] as constdepending on your requirements.