Wednesday, 21 April 2021

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

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

enter image description here

but this has proper typing

enter image description here

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.



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

No comments:

Post a Comment