type A {
a: string,
}
type B {
b: number
}
const data: A | B = { a: 'Hello' }
if((data as A).a !== undefind) {
// data is A
}
Created
June 26, 2021 04:08
-
-
Save ThaddeusJiang/dc84edc850772d405ae8a7520fd2cd5a to your computer and use it in GitHub Desktop.
TypeScript assert Type
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
调查了很多方法,这个方法最简单。