TypeScript types Object.keys to return string[] instead of (keyof T)[] due to its structural type system. Because an object typed as T may contain additional properties at runtime that TypeScript isn't aware of, returning keyof T would be unsafe — it could lead to accessing undefined validators or properties. The post explains

7m read timeFrom alexharri.com
Post cover image
Table of contents
Unsafe usage of Object.keysMaking use of structural typing

Sort: