To test if a value is of a certain type in TypeScript, you can use the typeof
operator. However, when using Scala with TypeScript, you will need to use a library like scala-js
to interact with TypeScript types. Here's an example of how you can test if an object is of a certain type using scala-js
.
187 chars10 lines
In the code above, we're using the type-detect
library to check the type of the value
variable. If it's a string
, we print a message saying that it's a string. If not, we print a message saying that it's not a string.
Note that you'll need to install the type-detect
library with npm
before you can use it in your Scala project.
gistlibby LogSnag