microsoft / microsoft/TypeScript

Simplify error messages against intersections of weak types

Open
#24,146 2 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Error Messages Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

I spoke a bit with @sandersn about ways we can tackle the type madness issue (#14662). I noted that JSX scenarios are much more broadly applicable right now and are pretty prevalent given the sorts of type arithmetic we see a lot of in the React community. 😃

Problem: JSX optional attributes make errors too hard to read

interface FooProps {
    name: string;
    age: number;
}

class Foo extends React.Component<FooProps> {
    constructor(props: FooProps) {
        super(props)
    }
    render() {
        const {name, age} = this.props;
        return <div>I'm {name} and am {age} years old</div>;
    }
}

// Type '{ blah: number; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Foo> & Readonly<{ children?: ReactNode; }> & Reado...'.
//   Type '{ blah: number; }' is not assignable to type 'Readonly<FooProps>'.
//     Property 'name' is missing in type '{ blah: number; }'.
<Foo blah={10} />;

Proposal

When doing relation checks against an intersection target, if a check fails, see if relating against the same type with weak types removed would result in the same outcome. If so, use that comparison when elaborating types.

The great part is that this actually solves a broader set of problems than just JSX.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the JSX reproduction in the issue and trace the type-relation checks for an intersection target with weak types. Compare the current diagnostic with the proposed comparison that removes weak types; done means the JSX error is simplified without changing the relation result, while broader affected cases remain covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.