Description
openedon Dec 11, 2018
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.