microsoft / microsoft/TypeScript
Compiler error message improvement: Special casing container objects
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
array promise container error message compare
Suggestion
Could it be worth having an extra special case message when the only difference is that you haven't included an array indicator instead of listing the property differences e.g.
3.7:
src/index.ts:356:5 - error TS2322: Type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; }[][]' is not assignable to type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; }[]'.
Type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; }[]' is missing the following properties from type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; }': renderedMessage, id, category, code, start
356 errors,
~~~~~~
src/index.ts:235:3
235 errors: {
~~~~~~
The expected type comes from property 'errors' which is declared here on type 'TwoSlashReturn'
To:
src/index.ts:356:5 - error TS2322: Type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; length: number | undefined; }[][]' is not assignable to type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; length: number | undefined; }[]'.
Type '{ renderedMessage: string; id: string; category: 0 | 1 | 2 | 3; code: number; start: number | undefined; length: number | undefined; }[]' is in an array here:
356 errors,
~~~~~~
src/index.ts:235:3
235 errors: {
~~~~~~
But not here
and the reverse?
Use Cases
Any case of mismatched types where the difference is that the object on one side of the comparison is the same object but wrapped in an array. Perhaps this could also work for a Promise too?
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the array-mismatch example and the linked Promise example in the TypeScript playground. The issue names no compiler files or tests, so trace the diagnostic-generation path after establishing the current output; done means the requested container-specific diagnostics are covered without changing runtime behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100