Reputation: 2815
I have a large typescript file that I've inherited. The compiler has many complaints with this file, however it works just fine.
I'll come back to it, but is there any way to suppress all warnings/errors in a specific file?
Upvotes: 127
Views: 172292
Reputation: 3288
You can use // @ts-nocheck
at the top of the file
Files
// @ts-nocheck
import lodash from lodash;
//your code here...
Look how its done in the code above.
UPDATE (2024): If you are getting the Do not use "@ts-nocheck" because it alters compilation errors.
message, then try adding the following line:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
Check references.
https://devblogs.microsoft.com/typescript/announcing-typescript-3-7/ https://github.com/microsoft/TypeScript/wiki/Type-Checking-JavaScript-
Upvotes: 221
Reputation: 439
I had to use // @ts-expect-error <message_explaining_use>
because a library I was using hardcoded true
and false
as type values instead of boolean
. This suppressed the next line and it worked. This was for typescript 5.2.2.
Docs reference: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-ts-expect-error-comments
Upvotes: 0
Reputation: 6587
If you are using Astro (and vanilla JS) you can add // @ts-nocheck
to the top of the <script>
tag (the client side script) to silence all the Typescript errors in your .astro
files. It saves from adding // @ts-ignore
to each line.
<script>
// @ts-nocheck
window.dataLayer = window.dataLayer || []
// other GA nonsense...
</script>
Upvotes: 2
Reputation: 33908
You could also use loose-ts-check to filter out and ignore some or all TypeScript errors in specific files.
It's used like this after initial setup:
tsc --noEmit | npx loose-ts-check
Upvotes: 4
Reputation: 11548
// @ts-ignore
comments
for lines// @ts-nocheck
after version 3.7 for the whole file.Upvotes: 65
Reputation: 19947
This is a little known trick. 2 steps:
/// <reference no-default-lib="true"/>
{
"compilerOptions": {
"skipDefaultLibCheck": true
}
}
Side note, as of 2019.4.11, skipDefaultLibCheck
option is marked as DEPRECATED in the doc, but the feature still exists in source code, see this line.
Upvotes: 10