How should I use Try/Catch in TypeScript? I don't want it to check for any errors in a given block because I already check for them (the error is expected and the state is controlled by the catch).
I have the code wrapped in Try/Catch (just example):
try {
let data = localStorage.getItem('something');
// Err. TS2345; I know, that's why you're in the try block
data = JSON.parse(data);
// Err. TS2531; I know, that's why you're in the try block
data.exp = new Date(data.exp * 1000);
return data;
} catch {
return null;
}
TypeScript refuses to compile it. Is there any way I can tell TypeScript that I know about the error and I'm okay with it? I don't want to use //@ts-ignore
on every line (assuming I can have a longer code) and I don't want to turn off strict mode. Is there any better solution?