In my JavaScript projects, I aim to include TypeScript types sparingly to leverage IntelliSense for better code completions and receive warnings about type-related issues.
To set up typechecking in JS, I created a jsconfig.json
file and rely mostly on JSDoc annotations to define the types, which has proven effective so far.
Now, I want to establish some common types to use across my project. Although I attempted to do this with a types.d.ts
file, it seems to be React-specific and lacks documentation.
I also experimented with storing the types in an index.d.ts
file, but encountered limitations as it is only recognized when importing from the index and not applicable to components that implement exports from the index.
The directive
/// <reference types="." />
did not bring the types from index.d.ts
into the current scope either. As a workaround, I had to specify each type individually using /** @typedef {import('.').Foo} Foo */
in the current file.
Is there a streamlined and sustainable approach to handling typescript types while predominantly writing code in javascript?