Add plugins methods to typescript definition
See original GitHub issueShould plugins’s api methods be added in the core d.ts
file? Or they should have their owns?
If they have their own, they should be merge into one when bundling the package?
I’m trying to use this library at another library, which is written with Typescript, and trying to use plugin methods, it’s driving me crazy. Any thoughts?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:41 (21 by maintainers)
Top Results From Across the Web
Module: Plugin - TypeScript: Documentation
Some plugins add or modify top-level exports on existing modules. While this is legal in CommonJS and other loaders, ES6 modules are considered...
Read more >How to Build A Plugin System with TypeScript
Defining a plugin. We'll define our plugins using an abstract class that is implemented by each plugin. We'll require name and version to...
Read more >javascript-plugin-architecture-with-typescript-definitions - npm
A custom class can be composed of the core Base class, a set of plugins and default options and distributed as new package,...
Read more >Is there a way to add methods on the fly to a class using ...
As an example of this, if you install a jQuery plugin you'll want to re-define the IJQuery & IJQueryUtil interface to include the...
Read more >Typescript - Strapi Developer Docs
Existing JavaScript projects can add TypeScript support through a conversion procedure. TypeScript-enabled projects allow developing plugins ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I updated PR #418, another plugin type defs with module augmentation.
I think it is reasonable to stick on
import dayjs from 'dayjs'
singleton (not re-exporting extend()ed instance of dayjs) for convenience, because we (at least I) don’t want to change installed plugins place-by-place.It is same as Vue’s plugin architecture, and official firebase plugin uses module augmentation to extend type declaration of Vue itself. Looks widely accepted way 😃
@iamkun option 3 isn’t necessarily a breaking change (though it can be). Consider that
extend
can still modify the prototype, and also return the new instance. This means that any existing usage will still work, but to get type safety you’ll need to re-export the instance created by theextend
call. Regarding multiple plugins that relay on one another - you can chain them together (or even modify theextend
method to take in an array of plugins):The latter is similar to how
Object.assign
is defined and behaves as.Do note that order is important here, so if
AdvancedFormat
would depend onRelativeTime
being defined, the above would fail (the other way around though would work). Again, somewhat similar to howObject.assign
behaves in regards to overriding properties defined in multiple objects.