How can I cast custom type to primitive type?

You cannot cast from a custom to a primitive without erasing the type first. unknown erases the type checking.

Try :

myRating as unknown as number

Or :

myRating as any

Also, remove | number from your declaration.

Leave a Comment