How to determine the type of import variable

I have noImplicitAnyinstalled trueTypeScript for my compiler. When I use import, as shown below, it throws an error because I do not explicitly define the type for the variable foo:

import * as foo from "bar";

I can determine the type for foousing the CommonJS require syntax:

const foo: FooType = require("bar");

Is there a way to determine the type for foousing syntax import * as ...?

+4
source share
1 answer

I think you mean something like ...

import * as foo: IFoo from "foo"

or

import foo : IFoo from "foo"

Is this accurate?

This was discussed, but ultimately a decision was made against.

, declare module 'bar' . import * as foo from "bar" .

.

:

untyped.d.ts

declare module "bar" {
    const foo:IFoo;
    export = foo;
}

tsconfig.json

{
    "compilerOptions": {
        ...
    },
    "include": [
        "untyped.d.ts",
        "src/**/*.ts",
        "src/**/*.tsx"
    ]
}

"untyped.d.ts" , . , .

p.s. files array, include , , , , files exclude, . . .

+4

Source: https://habr.com/ru/post/1673059/


All Articles