TypeScript "Compiler" Property does not exist on type '{}'


#1

Hi,

again i have a strange problem i dont understand:

I have a promise which resolves an array i called “items”.

Then i “call” this promise to get the array:

this.testSearch(value.value).then(items => {

           console.log(items)   //WORKS (its obviously an Array)

           console.log(items.slice())   //TypeScript Error: Property 'slice' does not exist on type '{}'.

    });

The TypeScripte “Compiler” obviously does not “know” that items is an Array ? How can i solve this ?

Thank you :slight_smile:


#2

You declare testSearch to return Promise<Array> (or Promise<Foo[]>.


#3

Thank you !

This works now :slight_smile:

return new Promise <Array<string>> (function (resolve, reject) {…
});


#4

You probably don’t really want to be creating a new Promise explicitly, but that’s another topic.