I have some Javascript code that imports the messageformat
module. This module can be used like this:
const MessageFormat = require('messageformat');
const mf = new MessageFormat("en-US");
const text = mf.compile(...);
This module exports a class, but it doesn't have a typings file. I created the following typings file:
declare module "messageformat" {
export class MessageFormat {
constructor(locale: string);
public compile(messageString: string): string;
}
}
In my Typescript code I now use it as:
import { MessageFormat } from "messageformat";
const mf = new MessageFormat("en-US");
const text = mf.compile(...);
Unfortunately, this doesn't generate new MessageFormat("en-US")
, but it generates new messageformat_1.MessageFormat("en-US")
which fails. I also tried the following approach:
declare module "messageformat" {
export default class MessageFormat {
constructor(locale: string);
public compile(messageString: string): string;
}
}
In my Typescript code I now use it as:
import MessageFormat from "messageformat";
const mf = new MessageFormat("en-US");
const text = mf.compile(...);
But this compiles to new messageformat_1.default('en-US')
which is also not correct. How do I create the typings file (and how do I import the module) so the proper class is constructed?