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

Add @ts-ignore-enable @ts-ignore-disable #40267

Closed
wants to merge 3 commits into from

Conversation

ShuiRuTian
Copy link
Contributor

Fixes #19573

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 26, 2020
@ShuiRuTian ShuiRuTian changed the title Add @ts-ignore-enable region Add @ts-ignore-enable @ts-ignore-disable Aug 26, 2020
@ShuiRuTian
Copy link
Contributor Author

ShuiRuTian commented Aug 26, 2020

This PR add two directives ts-ignore-enable and ts-ignore-disable.

  1. if only use ts-ignore-enable, the rest part is all ignored.
...   <-- this is normal
// @ts-ignore-enable
XXX    <-- this is ignored
...    <-- this is ignored
  1. you could add same directives for many times, but they only work for once.
// @ts-ignore-enable
XXX  <-- this is ignored  
// @ts-ignore-enable       <-- you could remove this line.
YYY   <-- this is ignored
// @ts-ignore-disable
ZZZ   <-- this is normal
// @ts-ignore-disable      <-- you could remove this line.
  1. // @ts-ignore-disable could be used alone, nothing would happen.

  2. @ts-expect-error would not work in the ignored region

// @ts-ignore-enable
XXX  <-- this is ignored
// @ts-expect-error       <-- No error message. whatever next line has error or not.
YYY   <-- this is ignored
  1. no region label, they are just comment.
// @ts-ignore-enable A
XXX  <-- this is ignored  
// @ts-ignore-enable   B    <-- you could remove this line.
YYY   <-- this is ignored 
// @ts-ignore-disable B
ZZZ   <-- this is normal
// @ts-ignore-disable A     <-- you could remove this line.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reasons that @weswigham gave for not doing this are pretty good. I'm voting no unless we change our minds on the original bug.

@ShuiRuTian
Copy link
Contributor Author

Yep, I strongly agree.

I give this PR because one comment is really interesting. #19573 (comment)

And maybe this PR could let community try giving more persuasive reasons, rather than just asking for it again and again.

@MathiasKandelborg
Copy link

I would like to reiterate my comment, that hasn't gotten a response from the team.

@kumar303
Copy link

kumar303 commented Oct 21, 2020

See resolution in #40267 (comment)

In support of this PR (thank you), I'd like to mention that it's currently impossible to selectively ignore styled-components errors since they are within template strings. This approach of @ts-ignore-enable + @ts-ignore-disable probably makes that possible but I did not confirm it.

@ShuiRuTian
Copy link
Contributor Author

@kumar303 Auh, not sure whether I get the point. But I download styled-componets and @type/styled-components and have following code

import styled, { css } from 'styled-components'

const Button = styled.button`
  ${props =>
    css`
      background: palevioletred;
      color: white;
    `};
`

I do not get any error(at least in my simple ts-config).

Now make a little change to add error:

const Button = styled.button`
  ${props =>
    props.primary &&  // ts(2339) on text `primary`
    css`
      background: palevioletred;
      color: white;
    `};
`

Adding the new @ts-ignore-enable directive at the start does make the error quiet, but this also work

// adding @ts-ignore-enable here could work
const Button = styled.button`
  ${
    // @ts-ignore         this line is not needed, just remind that the prop could be ignored in this way too
    props =>
    // @ts-ignore
    props.primary &&  // no error message now!
    css`
      background: palevioletred;
      color: white;
    `};
`

Do I get your meaning correctly? If not, could you give simple steps or a minimal repository to help me get it? Thanks!

@kumar303
Copy link

Aha! I stand corrected. The original code I was fighting with looked more like this (if memory serves):

import React from "react";
import styled from "styled-components";

const Button: React.FC<{
  // Since this is missing className and style props, it is invalid.
  nope: string;
}> = () => <button />;

const Form = styled.form`
  ${Button} {
    color: rebeccapurple;
  }
`;

The error happens at ${Button} but I was able just now to successfully put a @ts-ignore on top of that, like:

const Form = styled.form`
  ${// @ts-ignore
  Button} {
    color: rebeccapurple;
  }
`;

As I recall, I was unable to put @ts-ignore on top of this before. Perhaps a bug was fixed in either TS or prettier since I last tried or I'm remembering it wrong 😀.

@ShuiRuTian
Copy link
Contributor Author

Seems the issue is resolved.
I would not be so suprised if it is really due to the version of TS. TS might fix many small issues which would not be mentioned in the "new feature bolg" for each big version.
Personally, I recommand updating TS in time. TS is always getting better and better!

@sandersn
Copy link
Member

I remember seeing a PR for that fix in the last couple of months.

@ShuiRuTian do you want to keep working on this? If not, we can close it in its current state and restart work again later if something changes.

@ShuiRuTian
Copy link
Contributor Author

@sandersn

I would be glad to continue working on this again when TS team decides to have this feature someday.

@ShuiRuTian ShuiRuTian closed this Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

@ts-ignore for the block scope and imports
6 participants