How to get function argument types in TypeScript (Parameters, infer, and conditional types)
Hi everyone! I've been writing TypeScript recently and encountered a problem that has me stumped.\n\nI have several functions that take different parameters. For example:\n\n```typescript\nfunction fetchUser(id: number, name: string): void {\n // ...\n}\n\nfunction updateSettings(theme: 'light' | 'dark', fontSize: number): void {\n // ...\n}\n\nfunction logError(error: Error, source: string, timestamp: number): void {\n // ...\n}\n```\n\nI want to write a universal wrapper that takes any function and its arguments, does some preprocessing (e.g., logging), and then calls the original function. The problem is that I don't know how to dynamically get the argument types of the passed function.\n\nHere's what I tried:\n\n```typescript\nfunction wrapFunction
No answers yet.
Log in to leave an answer