假设有个第三方库的源码:
type MyType = { a: string, b: number }
export const fn = (props: MyType) :void => {
...
}
我们想在自己的代码中使用这个MyType,但它又没有export出来,该怎么办呢?
只需善用Utility Types
type Props = Parameters<typeof fn>[0]
如果想拿到MyType里的a:
type Props = NonNullable<Parameters<typeof fn>[0]>['a']