I have some React+TypeScript code that makes use of a component from a third party library.
<ThirdPartyComponent onSelect={(value: any) => {...}} />
eslint-typescript is identifying this as an issue:
Unexpected any. Specify a different type. eslint(@typescript-eslint/no-explicit-any)
The type definition of the select handler uses any:
export interface ThirdPartySelectCallback extends React.EventHandler<any> {
(value: any, e: React.SyntheticEvent<{}>): void;
}
What is the proper way to avoid this issue without disabling the eslint rule?
Changing the type to string gives a different error:
<ThirdPartyComponent onSelect={(value: string, e: React.SyntheticEvent<{}>) => {...}} />
Type '(value: string, e: SyntheticEvent<{}, Event>) => void' is not assignable to type 'ThirdPartySelectCallback'
onSelect={(value: string)? Or just add// eslint:disable-linebecause you cannot control a third party component - user6269864