Typescript小貼士:Type Guard

littlecodeguy
·
·
IPFS
·
Array Manipulation 經常用到 `filter()` 但 typescript 唔會幫你 infer 個 output type,所以好多時都要用 `as` 去 override 個 type, 但最好嘅方法係用 type guard function 去比 hint typescript。

Array Manipulation 經常用到 `filter()` 但 typescript 唔會幫你 infer 個 output type,所以好多時都要用 `as` 去 override 個 type, 但最好嘅方法係用 type guard function 去比 hint typescript。

https://littlecodeguy.com/post/2022-08-02-arr-type-guard/…


CC BY-NC-ND 2.0

Like my work? Don't forget to support and clap, let me know that you are with me on the road of creation. Keep this enthusiasm together!