Closed
Description
TypeScript Version: 2.5.3
Code
interface IFooProps {
key: string
value: number
}
interface IBarProps {
key: string
value: number
something: any
}
const Foo = (props: IFooProps) => {
return (
<div />
)
}
const barProps: IBarProps = {
key: 'foo',
value: 1,
something: 'something'
}
const Test1 = () => {
// I'm setting the `something` property which isn't defined in the `Foo` component (compile-time error). This is a correct behavior.
return <Foo key={barProps.key} value={barProps.value} something={barProps.something} />
}
const Test2 = () => {
// However, I can set the `something` property using the spread operator and the TypeScript compiler will not throw any error ---> Is this a bug?
return <Foo {...barProps} />
}
Expected behavior:
- Test1 throws the
[ts] Property 'something' does not exist on type 'IntrinsicAttributes & IFooProps'
error. - Test2 throws the
[ts] Property 'something' does not exist on type 'IntrinsicAttributes & IFooProps'
error.
Actual behavior:
- Test1 throws the
[ts] Property 'something' does not exist on type 'IntrinsicAttributes & IFooProps'
error. - Test2 throws no error.