Skip to content

JSX.ElementChildrenAttribute values are never considered excess properties in JSX #28953

Open

Description

TypeScript Version: 3.2.1

Search Terms: JSX children excess

Code

import React from 'react'

function Test(_: { foo: boolean }) { return null }
const x = <Test foo>foo</Test>

Expected behavior:
The foo string (JSXText) should be considered an excess property

Actual behavior:
children (JSX.ElementChildrenAttribute's key) are always allowed as excess properties when there is at least some overlap.

If Test's props were {} there is an excess property warning, but not when they are written as they are in this example.

Related Issues: I found this while working on DefinitelyTyped/DefinitelyTyped#30775, where fixing bugs related to ReactNode's types forced me to remove the implicit children prop added by the component types (they break render prop children).

It wasn't always possible to find through the test suite where components that needed to declare they accept children were missing that declaration, because almost always they'd pass strict test even when children was an excess, undeclared property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitter

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions