Does ES6 Promise require an argument in typescript 2.0?

I continue to work on an existing typescript project. The original project uses gulp - typescript to compile .ts files, but I use the tsc compiler that comes with Visual Studio code. But I can not get ES6 promises to work.

I installed the definition file for ES6 promises:

npm install --save @types/es6-promise

This creates a directory inside the node_modules folder with the promise definition file:

node_modules
    @types
        es6-promise
            index.d.ts
            package.json
            types-metadata.json
            readme.md

tsconfig.json

"files": [
    "src/main.ts",
    "src/game.ts",
    "node_modules/@types/es6-promise/index.d.ts"
]

link

///<reference path="../node_modules/@types/es6-promise/index.d.ts" />

I assume that including the promise definition file now works, but when compiling the project, I get the following error:

error TS2314: Generic type 'Promise<T>' requires 1 type argument(s).

When I look in the source code, I find this:

    private componentsPromise: Promise<Component[]>;
    private startPromise: Promise; // <- error

    public getComponents(): Promise<Component[]> {
        return this.componentsPromise;
    }

    public isStarted(): Promise {   // <-- error
        return this.startPromise;
    }

Is this a simple mistake in the original project, or am I missing something? What do I need to add here to run promises again?

+4
1

, . , , .then(x => ...), x? .

, . /, Promise<void>. , , Promise<any>, .

+6

Source: https://habr.com/ru/post/1656249/


All Articles