Envelop v2 documentation (superseded by v4): TypeScript Support
If you are using TypeScript with envelop, you can leverage the ability to infer types and have
complete type-safety.
For Plugin Developers
As a plugin developer, you can define the context properties you are contributing. This will make
sure to follow across the execution of your plugin, and you can leverage type-safety across all
hooks.
As a user of a plugin, you get type-inference based on the plugins that you use, for example:
// At this point, the context known to envelop is `{ pluginA: string, pluginB: string }`const getEnveloped = envelop({ plugins: [ usePluginA(), // Defined with Plugin<{ pluginA: string }> usePluginB() // Defined with Plugin<{ pluginB: string }> ]})server.on('req', async (req, res) => { // At this point, the context known to envelop is `{ pluginA: string, pluginB: string, req: Http.IncomingRequest }` const { parse, validate, execute, schema, contextFactory } = getEnveloped({ req }) // At this point, the context known to envelop is `{ pluginA: string, pluginB: string, req: Http.IncomingRequest, extra: boolean }` const context = await contextFactory({ extra: true })})
This site uses cookies for analytics and improving your experience.