I tried to create TypeScript types for this module, but couldn't figure out how to do it in combination with importing it as a module:
import * as computerName from 'computer-name'
I need to use the * as otherwise I get an error at runtime telling me tab3.tsx? [sm]:16 Uncaught TypeError: computer_name_1.default is not a function.
I can't manage to type this import and get computerName to be a function returning a string. Has someone done this?
Here is what I tried so far (content of my src/types/computer-name.d.ts):
export = computerName;
declare function computerName(): string;
It is not recognized when I import computer-name, it gives the standard warning about no types. When I add the suggested declare module 'computer-name':
declare module 'computer-name' {
export = computerName;
function computerName(): string;
}
TS now gives this warning: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.. esModuleInterop is on, so it seems to be the star import.
When I use const computerName = require('computer-name'), computerName will be typed as any, so that works for now, but it would be nice if I could get it correct.
I tried to create TypeScript types for this module, but couldn't figure out how to do it in combination with importing it as a module:
I need to use the
* asotherwise I get an error at runtime telling metab3.tsx? [sm]:16 Uncaught TypeError: computer_name_1.default is not a function.I can't manage to type this import and get
computerNameto be a function returning a string. Has someone done this?Here is what I tried so far (content of my
src/types/computer-name.d.ts):It is not recognized when I import
computer-name, it gives the standard warning about no types. When I add the suggesteddeclare module 'computer-name':TS now gives this warning:
This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export..esModuleInteropis on, so it seems to be the star import.When I use
const computerName = require('computer-name'),computerNamewill be typed asany, so that works for now, but it would be nice if I could get it correct.