Typescript: @ts-nocheck seems to be ignored on TS file

Created on 4 Sep 2018  Â·  8Comments  Â·  Source: microsoft/TypeScript

_From @arsnl on August 25, 2018 0:59_


  • VSCode Version: 1.26.1
  • OS Version: macOS High Sierra 10.13.6
  • TypeScript: 3.0.1

Steps to Reproduce

  1. Add // @ts-nocheck at the start of any TypeScript file
  2. Try to trigger any TS check error

Result

VS Code display TS error

error

Expected

VS Code should not display TS error


Does this issue occur when all extensions are disabled?: Yes

Snippet to try

// @ts-nocheck

const test = (foo: string) => `${foo}-bar`;

test(1); // Should not display error

test('baz'); // Correct behavior with correct type

// @ts-ignore
test(1); // Correct behavior with @ts-ignore

_Copied from original issue: Microsoft/vscode#57187_

In Discussion Suggestion

Most helpful comment

In the original design (#14496) the intent was for ts-check and ts-nocheck to only have meaning in JS files. The same was true with ts-ignore. We gave in to community demands for ts-ignore in TS code; so I suppose this now tracks the same for ts-nocheck.

All 8 comments

In the original design (#14496) the intent was for ts-check and ts-nocheck to only have meaning in JS files. The same was true with ts-ignore. We gave in to community demands for ts-ignore in TS code; so I suppose this now tracks the same for ts-nocheck.

any update ?

@hpmax00 if you read the comment just before yours, you can see this is intentional and is not a bug.

From experience (I’ve been there), you would need it for TS files only when something is not correctly configured in your editor or your project, so I advice you to double check your config :)

@martpie My situation is not as simply as you said just configuring the ide. You said it is intentional. Good job, your house your rules. Anyway thank you for reply.

@martpie I would find this most helpful especially in the transition to TypeScript or is there another elegant way to prevent files from being type checked?

@doberkofler without knowing much of your project, I’d say write JS files and enable TS’s allowJs compiler option.

But it defeats a little bit the purpose of TypeScript.

my use case for this is having a single file that does some on the fly metaprogramming that strict type checking in TS is not really designed for. But just adding one .js file to your app is nasty. for example I have my IDE setup to ignore JS files, to output in a certain place etc. So enabling to use hacky JS syntax in a single file is a benefit.

Was this page helpful?
0 / 5 - 0 ratings