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


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:

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

Thank you !

This works now :slight_smile:

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

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