Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress errors in .ts files using '// @ts-ignore' comments #18457

Merged
merged 1 commit into from
Sep 19, 2017

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Sep 13, 2017

We currently support suppressing errors in .js files using // @ts-ignore comments placed above the offending lines. With this PR we extend this support to .ts files as well. For example:

if (false) {
    // @ts-ignore: Unreachable code error
    console.log("hello");
}

A // @ts-ignore comment suppresses all errors that originate on the following line. It is recommended practice to have the remainder of the comment following @ts-ignore explain which error is being suppressed.

Fixes #9448.

@ahejlsberg ahejlsberg merged commit 8f4a2c1 into master Sep 19, 2017
@ahejlsberg ahejlsberg deleted the tsIgnoreInTSFiles branch September 19, 2017 23:59
@jhalborg
Copy link

jhalborg commented Oct 4, 2017

Hey :)

I can't seem to get this to work. I'm using TS 2.5.3 and VSCode 1.16.1, and I'm trying to ignore the warning I get in the following code.

import * as devConfig from './../../config.dev.json';
import * as prodConfig from './../../config.prod.json';

interface IConfig {
  instagram: {
    clientId: string;
    scopes: object;
  };
  urls: {
    authRedirectURL: string;
    baseAPIURL: string;
    termsURL: string;
  };
  googlePlacesAPIKey: string;
}

const getConfig = (): IConfig => {
  // @ts-ignore: Type 'typeof '*.json'' is not assignable to type 'IConfig'
  return __DEV__ ? devConfig : prodConfig;
};

export { getConfig, IConfig };

Did I miss something?

@ghost
Copy link

ghost commented Oct 4, 2017

@jhalborg This feature isn't in typescript@2.5, you'll have to install typescript@next.

@lmcarreiro
Copy link

couldn't it be done with the comment in the same line?

let v1: string = 1; // @ts-ignore
let v2: string = 2; // @ts-ignore
let v3: string = 3; // @ts-ignore
let v4: string = 4; // @ts-ignore
let v5: string = 5; // @ts-ignore
let v6: string = 6; // @ts-ignore

instead of:

// @ts-ignore
let v1: string = 1;
// @ts-ignore
let v2: string = 2;
// @ts-ignore
let v3: string = 3;
// @ts-ignore
let v4: string = 4;
// @ts-ignore
let v5: string = 5;
// @ts-ignore
let v6: string = 6;

@basarat
Copy link
Contributor

basarat commented Feb 25, 2018

couldn't it be done with the comment in the same line?

Suppresses error on the next line. Would be confusing if it did too much e.g.

error; // @ts-ignore < Would eat both errors? 
error; 

Simple does one well defined thing is better 🌹

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants