Doc comments missing from imported typed functions

103 Views Asked by At

I've ran into a problem when creating some react hooks. The hooks had their types and doc comments defined like this:

type UseA = () => {
  fnA: () => void;
  ...
}

/** Some hook */
export const useA: UseA = () => {
  ...
}

When I imported these hooks into my components the UseA type and the doc comments were missing. Instead VS Code just inferred the return types of the hooks.

import { useA } from './useA';
// here VSCode shows the original type definition and doc comments

...

const { fnA } = useA();
// here useA's type is just () => { fnA: () => void; ... } instead of UseA
// doc comments are also missing from the hook

After changing the hook's type so that only the return type is defined

type UseA = { fnA: () => void; ... };
const useA = (): UseA => { ... };

VS can now see the doc comments on useA() and it has the correct () => UseA type. My question is, why wasn't it working with the first type definition? Is this the intentional behavior? VS could see the type and docs in the import statement so why were they missing in the component? Maybe it has something to do with tsconfig?

0

There are 0 best solutions below