Function in javascript file can't detect its own type with declaration file

12

Is it possible for a file that has a corresponding declaration file to detect its own type in vscode?

Other files can get the typings, but not the file itself.

note the any

but this has proper typing

Reproduction

  1. Create a folder
  2. Run npm init
  3. Hit enter through everything
  4. Create 3 files index.js index.d.ts import.js

index.js

async function test(input) {
    return null
}

index.d.ts

type input_type = {
    name: string,
    salary: number
}

export function test(input : input_type) : Promise<null>

import.js

import * as t from './index'

t.test()

When you mouse over the test function in index.js it doesn't know its parameter type. But in import.js it knows it.

How can I get the index.js test function to know its own type.

Share
Improve this question
1
  • This typescript issue seems to be exactly about your problem: github.com/Microsoft/TypeScript/issues/14342. (With the resolution seeming to be essentially what TUTAMKHAMON mentioned in their answer.) – mihi Apr 26 at 20:51

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue