You may encounter this typescript issue in your React Native project with ease (for example after updating RN to the latest version)
The correct tygins for global functions are provided by the lib definition, though:
declare function setTimeout(handler: () => void, timeout: number): number;
declare function setTimeout<Args extends any[]>(
handler: (...args: Args) => void,
timeout?: number,
...args: Args
): number;
Source:
types/react-native/globals.d.ts
The primary issue is that @type/node
global types replace @type/react-native
global types.
And by default, typescript behaves in that way:
All visible ”@types” packages are included in your compilation.
Ok, then let's specify only that global typing that we actually need (tsconfig.json
):
{
"compilerOptions": {
"types": ["react-native", "jest"]
}
}
After modifying compilerOptions.types
nodejs typing will be exclude.
Read more:
Top comments (0)