You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
agh, rats. Thanks @dk4tz I thought this was working.
To be honest, I'm still pretty crap at typescript, and may be already past my level of competence. You really seem to know your stuff - wanna take a look? Any changes welcome, either advice or PR
cheers
I am not a TypeScript expert either, but I think the issue is that the return type annotation of nlp uses a generic, which will always default to an empty object.
I'm not sure if this the idiomatic way to handle module augmentation, but this approach seems reasonable (and, importantly, works):
// index.d.ts (compromise-dates)exportinterfaceDatesMethods{// methods go here}declare module 'compromise'{interfacePluginMethodsextendsDatesMethods{}}
This approach immediately augments the module when compromise-dates is pulled in.
One alternative could be to use the return type annotation of nlp.plugin() to infer the correct return type of subsequent calls to the object:
nlp.dates("today")// errorconstnlpWithDates=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.
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: