Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.8K
Visualizações
How to use `@ts-ignore` for a block?

The // @ts-ignore comment enables the TypeScript compiler to ignore the line below it.

How can one ignore a whole block of code with TypeScript?

over 4 years ago · Santiago Trujillo
6 Respostas
Responde à pergunta

0

You can't. This is an open issue in TypeScript.

over 4 years ago · Santiago Trujillo Relatório

0

You can't.

As a workaround you can use a // @ts-nocheck comment at the top of a file to disable type-checking for that file: https://devblogs.microsoft.com/typescript/announcing-typescript-3-7-beta/

So to disable checking for a block (function, class, etc.), you can move it into its own file, then use the comment/flag above. (This isn't as flexible as block-based disabling of course, but it's the best option available at the moment.)

over 4 years ago · Santiago Trujillo Relatório

0

If you don't need typesafe, just bring block to a new separated file and change the extension to .js,.jsx

over 4 years ago · Santiago Trujillo Relatório

0

There is

// @ts-nocheck

It can be added at the beginning of the file and all errors in it will be ignored, isn't the block specific answer you are looking for but in some scenarios it is equivalent.

https://devblogs.microsoft.com/typescript/announcing-typescript-3-7/#ts-nocheck-in-typescript-files

over 4 years ago · Santiago Trujillo Relatório

0

you can use // @ts-expect-error to suppress the error on one line, and you can do it for multiple lines ( a bit cumbersome)

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-ts-expect-error-comments

BUT WAIT

if you use // @ts-expect-error on line that has no error, it will result in error Unused '@ts-expect-error' directive.

so make sure to only use it on line that has type error

over 4 years ago · Santiago Trujillo Relatório

0

If you are using prettier you can add //prettier-ignore for code that is small enough that prettier just turned into more than one line

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda