ts is 类型保护
John Doets is 类型保护
1 2 3 4 5 6 7
| function isString(test: any): test is string{ return typeof test === "string";} function example(foo: any){ if(isString(foo)){ console.log("it is a string" + foo); console.log(foo.length); example("hello world");
|
https://segmentfault.com/a/1190000022883470