Answers for "how to check if a variable is of type string in typescript"

1

typescript if variable is string

if (typeof myVar === 'string' || myVar instanceof String)
// it's a string
else
// it's something else
Posted by: Guest on September-15-2021
3

typescript check type of variable

if (fooOrBar instanceof Foo){
  // TypeScript now knows that `fooOrBar` is `Foo`
}
Posted by: Guest on December-03-2020

Code answers related to "how to check if a variable is of type string in typescript"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language