I use a lib react-international-phone
for phone input integration and it exposes UsePhoneInputConfig
type, which looks like this,
type UsePhoneInputConfig = {
onChange?: (data: { phone: string }) => void;
};
Now in my wrapper component over this lib, i’ve handleOnChange
, which calls onChange
prop, and is assigned to the function type from the lib.
const handleOnChange: UsePhoneInputConfig['onChange'] = useCallback((data) => {
onChange(data.phone);
}, [onChange]);
And I was expecting the data type to be the object { phone: string }
, but it says Parameter 'data' implicitly has an 'any' type.ts(7006)
, when I make the onChange
a required type from UsePhoneInputConfig
, it infers the type properly.
Here is my tsconfig.json
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"downlevelIteration": true,
"target": "ES2021",
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"],
"@test/*": ["./test/*"],
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Note: With typescript lang demo it does work properly, and not sure which tsconfig options is making this issue.
1