If you're having trouble fixing the code, there are ways to suppress the error temporarily. One option is to use a comment like @ts-expect-error
:
// @ts-expect-error
const s: string = 123
Another option is to use @ts-ignore
:
// @ts-ignore
const s: string = 123
Wondering when to use @ts-ignore
or @ts-expect-error
?:
Choose ts-expect-error
if:
- you're writing test code and want the type system to flag an operation as an error
- you anticipate a quick fix and just need a temporary solution
- you're working on a project where the team actively removes suppression comments once the affected code is fixed
Choose ts-ignore
if:
- you're dealing with a large project and new errors have cropped up in code without a clear owner
- you're in the midst of upgrading between different TypeScript versions and encountering errors in one version but not in another
- you simply don't have the time to decide between these options
Check out this demo for more information.