Skip to content

Treating attribute in JSX as literal type #10393

@yuit

Description

@yuit

The original issue is issue #10171. Currently we don't treat property assignment of JSX element as literal type as issue #10171 illustrates

type TextProps = { editable: false }
               | { editable: true, onEdit: (newText: string) => void }

class TextComponent extends React.Component<TextProps, {}> {
    render() {
        return <span>Some Text..</span>;
    }
}

ReactDOM.render(
    <TextComponent editable={true} />, // editable is of type boolean not of type "true"
    document.getElementById("example")
);

One possible solution is to treat property as literal type instead. This could possibly affect how overload will work as well

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueDomain: JSX/TSXRelates to the JSX parser and emitterDomain: Literal TypesUnit types including string literal types, numeric literal types, Boolean literals, null, undefinedFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions