TypeStrong / atom-typescript

The only TypeScript package you will ever need
https://atom.io/packages/atom-typescript
MIT License
1.13k stars 205 forks source link

Suggestion: Show type inference in error messages #1230

Closed mrpinsky closed 4 years ago

mrpinsky commented 7 years ago

When displaying a type error involving primitive types, the linter currently displays the required type, but not the inferred type. I had a property that I thought was the correct type, but was actually a union of the correct type and an incorrect type, and it would have helped a lot to have had error messages like Elm's.

Example:

interface A {
  id: number | string;
}

const nIds: A[] = [{id: 1}, {id: 2}, {id: 3}];
const oddIds: A[] = nIds.filter(a => a.id % 2 == 1); // Error on a.id

Actual: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type Desired: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type, but got 'number | string'

github-actions[bot] commented 4 years ago

This issue has been marked as stale because it did not have any activity for the last 90 days or more. Remove the stale label or comment or this will be closed in 14 days