Typescript is String Check

Ole Ersoy
1 min readSep 7, 2020
Image by Clker-Free-Vector-Images from Pixabay

Scenario

We need to check if a variable is a string.

Approach

/**
* @param s
* @return true is s is a string false otherwise
*/
export function isString(s:any) {
return (typeof s === 'string' || s instanceof String) ? true : false
}

--

--