Skip to content

JSX Attributes should be considered mutable locations #20705

Description

@weswigham

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions