Skip to content

Ignored error in class constructor causes method usage errors to be ignored #36268

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

Open
katz12 opened this issue Jan 17, 2020 · 3 comments
Open
Labels
Bug A bug in TypeScript
Milestone

Comments

@katz12
Copy link

katz12 commented Jan 17, 2020

TypeScript Version: 3.5.3

Search Terms:
ts-ignore in class constructor
class method no error on parameter usage

Code

class Foo {
  bar: string
  constructor(bar: string) {
    this.bar = bar
  }

  baz(buzz: number) {
    return buzz + 1
  }
}

// @ts-ignore
const instance = new Foo()
instance.baz('buzz')

Expected behavior:
The invocation of instance.baz('buzz') should report that the parameter should be a number instead of a string.

Actual behavior:
There is no error on that line.
If I fix the ts-ignore on the line above, it then reports the error correctly.

Playground Link:
http://www.typescriptlang.org/play/?ts=3.8.0-dev.20200116#code/MYGwhgzhAEBiD29oG8BQ1oCMwCcBc0EALjgJYB2A5utMPOcTgK7BHw4AU2+hJFlAShQ0MRABakIAOm7QAvFlw0AvqhrYAXlyYaNBckwC2mAKY4haDBhwmiTHOSw6N0ANTQAjCtSrUAej9oAAEiCABaUkpydhNUOgYiaApiMHJgE3lochMAdzhEDgFUZKJU9JkwLQByTGcqgSA

Related Issues:
Could not find any through Google or here.

@DanielRosenwasser
Copy link
Member

This is confusing because from just hovering over instance, the type is Foo; however, I think what's happening is that we have different type-checker modes, and new Foo() produces something different from each type-checker.

new Foo() in our error-producing type-checker returns the internal error type that works like any because it tries to avoid cascading errors on subsequent operations. However, operations like quick info and auto-completerely on a more lax type-checker that tries to get results of operations in a best-effort way and produces the type Foo. However, that more relaxed checker isn't the same type-checker instance that produces errors, so you don't get an error on that subsequent operation.

@sheetalkamat @weswigham does that sound about right?

@weswigham
Copy link
Member

weswigham commented Jan 17, 2020

That is precisely it. See #28564 or #28950 for a possible fix.

@katz12
Copy link
Author

katz12 commented Jan 21, 2020

Thanks for the responses. I will focus on fixing type errors in constructors for now.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 6, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants