Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

JSX Attributes should be considered mutable locations #20705

Copy link
Copy link
@weswigham

Description

@weswigham
Issue body actions

TypeScript Version: 2.7.0-dev.201xxxxx

We do not perform mutability widening on jsx attributes as we do for object property assignments. Since we do not do the same kind of inference on jsx (and do not have generic jsx return types), this is difficult to witness (since the literal is compatible with its constraint), but is potentially a big performance hit for JSX users that was hidden. The example below is one case where the difference can be witnessed:

Code

function Bar<TSame>(props: {x: TSame, y: TSame}) {
    return <span />
}

<Bar x="a" y="b" />
Bar({
    x: "a",
    y: "b"
})

Expected behavior:
Bar's quickinfo shows Bar<string> on both styles of call - TSame is not constrained to string or another literal domain, so its use sites should not be literal locations.

Actual behavior:
Bar's quickinfo shows Bar<"a" | "b"> for the JSX call, but Bar<string> for the normal call.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitterRelates to the JSX parser and emitterFixedA PR has been merged for this issueA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.