Skip to content

AllowJs - ts-check - Cannot find namespace #19547

@jantimon

Description

@jantimon

Code

node_modules/@types/thirdParty/index.d.ts

export = demo;
declare namespace demo {
  foo: number;
}

main.js

// @ts-check
/// <reference types="thirdParty" />
const x: demo.foo;

Expected behavior:

I should be able to use the type foo of demo.
The example from above would work if but only if the thirdParty plugin also exports its namespace:

export as namespace demo;

I couldn't find any docs on what exactly export as namespace does.
Proably it would just add it to the global namespace which might not be the desired solution.

Actual behavior:

Without the exported namespace I receive error messages which are not helpful at all:

error TS2304: Cannot find name 'demo'
error TS2503: Cannot find namespace 'demo'

Suggestion:

Could we import everything which is exported from the index.d.ts file (like export = demo) to a name?
This would be useful for --allowJs checks where we can't import typings from another file.

// @ts-check
/// <reference types="thirdParty" name="thirdParty" />

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions