Skip to content

Error messages should place most relevant information first. #29759

Open
@CyrusNajmabadi

Description

@CyrusNajmabadi

Here's an actual example of an error message that can go wrong in our library when mispelling a property when creating an object literal:

[ts]
Type '{ containers: { nginx: { image: string; memory: number; portMappings: NetworkListener[]; enviroment: number; }; }; }' is not assignable to type 'FargateTaskDefinitionArgs'.
  Types of property 'containers' are incompatible.
    Type '{ nginx: { image: string; memory: number; portMappings: NetworkListener[]; enviroment: number; }; }' is not assignable to type 'Record<string, Container>'.
      Property 'nginx' is incompatible with index signature.
        Type '{ image: string; memory: number; portMappings: NetworkListener[]; enviroment: number; }' is not assignable to type 'Container'.
          Object literal may only specify known properties, but 'enviroment' does not exist in
          type 'Container'. Did you mean to write 'environment'? [2322]

- fargateService.d.ts(169, 5): The expected type comes from property 'taskDefinitionArgs'
  which is declared here on type 'FargateServiceArgs'

The funny thing here is that the final parts of the error message are superb. Namely:

- Object literal may only specify known properties, but 'enviroment' does not exist in
  type 'Container'. Did you mean to write 'environment'? [2322]

- fargateService.d.ts(169, 5): The expected type comes from property 'taskDefinitionArgs'
  which is declared here on type 'FargateServiceArgs'

However, the actual output is quite cluttered and hard to glean the information from. This is esp. true in an ide setting where one sees something like this:

image

This view is particularly problematic due to the wrapping and wall-of-goop nature of this type of error.

My suggestion would be to invert the information being provided by errors. Give the most specific and directly impactful information first (i.e. Object literal may only specify known properties, but 'enviroment' does not exist in type 'Container'. Did you mean to write 'environment'?), and then follow that up with all the extra details that can be used to dive deeper into things when that isn't clear enough.

Metadata

Metadata

Labels

Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions