The setup is a “Create React App” with the following jsconfig.json
:
{
"compilerOptions": {
"experimentalDecorators": true,
"baseUrl": "src"
},
"include": ["src"]
}
The directory structure:
.
└── src
└── Components
└── Foo
├── Bar
│ ├── Bar.js
│ ├── Bar.d.ts
│ └── index.js
├── Foo.js
└── index.js
// React component `Foo` imports a component `Bar`:
import { Bar } from './Bar'
export function Foo(props) {
//
}
// And gets full intellisense via `Bar.d.ts`:
type Props = {
/** ... */
}
export declare function Bar(
props: Props
): React.FunctionComponent
But Bar.js
itself doesn’t get intellisense from its own Bar.d.ts
file, is there a way to fix it? I tried the triple-slash directive (/// <reference path="Bar.d.ts"/>
), but it didn’t help. Some JSDoc helped, but it’s rather pointless to have a dedicated declaration file and still use JSDoc; it also probably only works with VSCode, which is undesirable:
export function Bar(
// When `type Props` is exported from the `.d.ts`:
/** @type {import("./Bar").Props} */ props
) {
You can access the IntelliSense page by choosing Tools > Options on the menu bar, and then expanding Text Editor > JavaScript/TypeScript > IntelliSense. Your computer might show different names or locations for some of the Visual Studio user interface elements in this article.
IntelliSense# Visual Studio Code's JavaScript IntelliSense provides intelligent code completion, parameter info, references search, and many other advanced language features. Our JavaScript IntelliSense is powered by the JavaScript language service developed by the TypeScript team.
As of September 2020, this is intended (source):
[...] there is no supported scenario for "the .d.ts is a sidecar to the .js". The recommended thing to do here is use JS Doc to write your type annotations.
Follow TypeScript’s development to see if it changes in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With