Closed BlueSky1997AL closed 4 years ago
In the following codes:
import PropTypes from 'prop-types'; import React from 'react'; export interface TestProps<T> { value?: T; onChange?: (param1: string, param2: number, param3: boolean) => void; } class Test<T> extends React.Component<TestProps<T>> { public static propTypes = { onChange: PropTypes.func }; } const el: JSX.Element = <Test onChange={(p1, p2, p3) => console.log(p1, p2, p3)} />; export default Test;
The onChange attribute of Test component should be in ((param1: string, param2: number, param3: boolean) => void) | undefined type like this:
onChange
Test
((param1: string, param2: number, param3: boolean) => void) | undefined
But when I pass a function into this attribute, I get a type error: Parameter 'p1' implicitly has an 'any' type. ts(7006)
Parameter 'p1' implicitly has an 'any' type. ts(7006)
When I modify value?: T; to value?: T[];, it works as expected:
value?: T;
value?: T[];
Remove propTypes also works:
propTypes
Remove generics also works:
Is this a problem with prop-types?
prop-types
typescript@3.5.3
react@16.9.0
prop-types@15.7.2
This repo has no types; perhaps you mean to file an issue on DefinitelyTyped?
Opps, I didn't notice that, sorry. I will file an issue on DefinitelyTyped, thanks a lot.
Description
In the following codes:
The
onChange
attribute ofTest
component should be in((param1: string, param2: number, param3: boolean) => void) | undefined
type like this:But when I pass a function into this attribute, I get a type error:
Parameter 'p1' implicitly has an 'any' type. ts(7006)
When I modify
value?: T;
tovalue?: T[];
, it works as expected:Remove
propTypes
also works:Remove generics also works:
Is this a problem with
prop-types
?Environment
typescript@3.5.3
react@16.9.0
prop-types@15.7.2