Skip to content

The intellisense for Foo.js is provided via a corresponding Foo.d.ts only when it’s imported somewhere—in a different file, but not in the Foo.js itself. #40097

@awgv

Description

@awgv
  • VSCode Version: 1.47.3 (system setup)
  • OS Version: Windows_NT x64 10.0.19041

Here’s a contrived directory structure of a React app:

.
└── src
    └── Components
        └── Foo
            ├── Bar
            │   ├── Bar.js
            │   └── Bar.d.ts
            └── Foo.js
// React component `Foo` imports a component `Bar`:

import { Bar } from './Bar/Bar'

export function Foo() {
  //
}
// 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—it’s like the .d.ts doesn’t exist—am I doing something wrong, or is it how it’s supposed to work in the current version of VSCode? 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:

export function Bar(
  // When `type Props` is exported from the `.d.ts`:
  /** @type {import("./Bar").Props} */ props
) {

I tried the Insiders build—same thing. I also prepared a repository representing the example above in case you want to check something yourself. Initially, I asked it as a StackOverflow question (link), but didn’t get an answer, so if you think this is a usage question, please leave an answer there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions