Jordan
Jordan

Reputation: 307

Cannot find name 'Math'

I am learning Angular7 and following tour-of-heroes application. I created InMemoryDataService class and trying to generated id but getting Error "[ts] Cannot find name 'Math'." I also try to add Math package with NPM command but error is still there.

Tried to Install Math package with NPM command .

genId(users: User[] ): number {
    return (<any>users).length > 0 ? Math.max( ...(<any>users).map( user => user.userId ) ) + 1 : 11;
}

I am not able to use Math class.

Upvotes: 1

Views: 3397

Answers (1)

Lazar Ljubenović
Lazar Ljubenović

Reputation: 19764

Math is not a class; it's a global object required to exist by the ECMA specification in the global scope, so there's no need to install it (with npm or otherwise). It's just there and it should be available to you.

Make sure you're including at least the es5 lib in your tsconfig.json:

"lib": ["es5"]

Upvotes: 4

Related Questions