Promise.Prototype.FinalLyscript type definition

I use this ES6 Promise compatible final implementation called promise.prototype.finally in my Node application, I want to convert it to TypeScript, but I can’t find this on DefinitelyTyped Available types of packages. In these cases I wrote my own impromptu type definitions for the subset of functions I need, but in this case, it is a library that modifies the prototype of the Promise object, and I haven’t encountered any traditional way Express it in TypeScript. Any ideas?

May be related:

> https://github.com/Microsoft/TypeScript/issues/280
> https://github.com/Microsoft/ TypeScript/issues/7015
> https://github.com/Microsoft/TypeScript/issues/6722
> Declaration merging with ES6 style modules

Although Slava’s answer is correct, it only involves the input of the finally block. To actually incorporate the filler into the code so that you can write p.finally(() => {…}), you need to call the filler.

Unfortunately typings on DefinitelyTyped does not currently support the gasket function so until this is supported, I suggest you add these typewriters yourself.< /p>

declare interface Promise {
finally(onFinally?: () => U | Promise): Promise;< br />}

declare module'promise.prototype.finally' {
export function shim(): void;
}

These types are now available . During installation

npm install --save-dev @types/promise.prototype.finally

In TypeScript code, during application boot, You can call

import {shim} from'promise.prototype.finally';
shim();

This will finally block Added to the Promise prototype, allowing you to use finally as needed.

This ES6 Promise compatible final implementation named promise.prototype.finally is used in the Node application. I want to convert it to TypeScript, but I cannot find the available types for this package on DefinitelyTyped. In these cases I wrote me I need the definition of a subset of functions for my own improvisation type, but in this case, it is a library that modifies the prototype of the Promise object, and I haven’t encountered any traditional way of expressing it in TypeScript. Any ideas?

May be related:

> https://github.com/Microsoft/TypeScript/issues/280
> https://github.com/Microsoft/ TypeScript/issues/7015
> https://github.com/Microsoft/TypeScript/issues/6722
> Declaration merging with ES6 style modules

< p>Although Slava’s answer is correct, it only involves the input of the finally block. To actually incorporate the filler into the code so that you can write p.finally(()=> (…)), you need to call the filler

Unfortunately typings on DefinitelyTyped currently does not support the shim function so until this is supported, I suggest you add these typewriters yourself.

declare interface Promise {
finally(onFinally?: () => U | Promise): Promise;
}

declare module'promise.prototype.finally' {
export function shim(): void;
}

These types are now available. When installing

npm install --save-dev @types/promise.prototype.finally

In TypeScript code, during application boot, you can call

import {shim} from'promise.prototype.finally';
shim();

This will add the finally block to the Promise prototype, allowing you to use finally as needed .

Leave a Comment

Your email address will not be published.