Instantly share code, notes, and snippets.

Embed
What would you like to do?
type guard
/node_modules
interface Hoge {
value?: string
}
function printStr(s: string) {
console.log(s)
}
function a(hoge: Hoge) {
if (typeof hoge.value === 'string') {
printStr(hoge.value)
}
}
const h = { value: "a" }
a(h)
const h2 = { value: undefined }
a(h2)
{
"dependencies": {
"typescript": "^3.3.3"
}
}
{
"defaultSeverity": "warning",
"extends": [
"tslint:recommended"
],
"linterOptions": {
"exclude": [
"node_modules/**"
]
},
"rules": {
"quotemark": [true, "single"],
"indent": [true, "spaces", 2],
"interface-name": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"no-consecutive-blank-lines": false
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
typescript@^3.3.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.3.tgz#f1657fc7daa27e1a8930758ace9ae8da31403221"
integrity sha512-Y21Xqe54TBVp+VDSNbuDYdGw0BpoR/Q6wo/+35M8PAU0vipahnyduJWirxxdxjsAkS7hue53x2zp8gz7F05u0A==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment