Martin Freeman
Martin Freeman

Reputation: 13

how to write .d.ts file for js file which export a pure object?

I'm trying add .d.ts file for existing js file.

type.js file like this:

// type.js
export default {
    NORMAL: '001',
    CHECK: '002',
};

And add type.d.ts file like this:

// type.d.ts
declare namespace col_type {
    const NORMAL: string;
    const CHECK: string;
}

But in my project, after import type.js, VSCode show error like this:

import TYPE from './type';

error:

File './type.d.ts' is not a module.

I honestly can't figure out what I should do here.

Upvotes: 1

Views: 2399

Answers (1)

brunnerh
brunnerh

Reputation: 184516

Your declaration file is missing the export:

declare namespace col_type {
    const NORMAL: string;
    const CHECK: string;
}
export = col_type;

Upvotes: 2

Related Questions