-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TypeScript Support for Compromise-Dates #1067
Comments
I am not a TypeScript expert either, but I think the issue is that the return type annotation of I'm not sure if this the idiomatic way to handle module augmentation, but this approach seems reasonable (and, importantly, works): // three.d.ts
export interface PluginMethods {}
declare function nlp(text: string, lexicon?: Lexicon): View & PluginMethods Then, in the plugin's declarations: // index.d.ts (compromise-dates)
export interface DatesMethods {
// methods go here
}
declare module 'compromise' {
interface PluginMethods extends DatesMethods {}
} This approach immediately augments the module when One alternative could be to use the return type annotation of nlp.dates("today") // error
const nlpWithDates = nlp.plugin(datePlugin);
nlpWithDates.dates("today") // no error This is technically safer, since it would only make TypeScript aware of plugin methods when a plugin is actually registered, but it also means that code in the wild would have to be rewritten to benefit. (It's also a little beyond my current TypeScript skills to implement, though I imagine I could figure it out.) Either way, I'm happy to put in a PR if this sounds reasonable. |
you do sound like a TypeScript expert! go for it! |
When using TypeScript and 'compromise-dates', the plugin methods do not appear on the base 'Three' type. This breaks compilation on TSC strict projects.
The text was updated successfully, but these errors were encountered: