Skip to content

Overly broad error span when function field not assignable to its annotation inside class #23515

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

Closed
kpdonn opened this issue Apr 18, 2018 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fixed A PR has been merged for this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this

Comments

@kpdonn
Copy link
Contributor

kpdonn commented Apr 18, 2018

TypeScript Version: 2.9.0-dev.20180414

Search Terms:
class error span, not assignable to type

Code

type Values = 1 | 2 | 3 | 4 | 5 | 6

type FuncType = (arg: Values) => string

// turn on strictNullChecks
class Example {
  insideClass: FuncType = function(val) { // error span goes from here
    switch (val) {
      case 1:
        return "1";
      case 2:
        return "2";
      case 3:
        return "3"
      case 4:
        return "4"
      case 5:
        return "5"
      // forgot case 6
    }
  } // all the way to here
}

const outsideClass: FuncType = function(val) { // compare to errors only on this line in this case 
    switch (val) {
      case 1:
        return "1";
      case 2:
        return "2";
      case 3:
        return "3"
      case 4:
        return "4"
      case 5:
        return "5"
      // forgot case 6
    }
}

Expected behavior:
Error on insideClass field would look similar to one on outsideClass variable.

Actual behavior:
Error on insideClass spans the entire function implementation.

Playground Link:
Link (Must turn on strictNullChecks to see error)

Related Issues:
Did not notice any duplicates when looking through Domain: Error Messages tag

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Help Wanted You can do this Good First Issue Well scoped, documented and has the green light Domain: Error Messages The issue relates to error messaging labels Apr 18, 2018
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Apr 18, 2018

PRs are welcome! I'd think this should be easy enough to tackle for anyone who wants to help out for the first time.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 20, 2018

@weswigham we should make sure that all errors on function expression nodes do not extend past the first line (if they are multi-line).

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label May 3, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fixed A PR has been merged for this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

4 participants