Monday, April 21, 2025

Show HN: I made TypeScript's type inference more strict (and smarter) https://ift.tt/MbiPZXW

Show HN: I made TypeScript's type inference more strict (and smarter) As a TypeScript developer, I often found myself wishing the type system could do more—*especially when omitting or modifying deeply nested properties* inside complex objects and arrays. For instance, what if I want to remove a deeply nested field like `user.profile.email` and also something like `user.posts[ ].meta.shares` from a type? TypeScript doesn't really provide a built-in way to do that. So I built *DeepStrictTypes* — a utility that lets you *omit deeply nested keys*, even inside arrays, with full type inference and strictness. Here’s an example: ```ts type Example = { user: { id: string; profile: { name: string; age: number; email: string; }; posts: { title: string; content: string; meta: { likes: number; shares: number; }; }[]; }; }; // Remove 'user.profile.email' and 'user.posts[ ].meta.shares' type Omitted = DeepStrictOmit< Example, 'user.profile.email' | 'user.posts[*].meta.shares' >; ``` The resulting type: ```ts { user: { id: string; profile: { name: string; age: number; }; posts: { title: string; content: string; meta: { likes: number; }; }[]; }; } ``` Works great for: - Cleaning up types for API responses - Dynamically transforming deeply nested data - Improving type safety when handling structured JSON [ https://ift.tt/X2FrN68 ]( https://ift.tt/X2FrN68 ) Would love your feedback or ideas for improvements! https://ift.tt/yFqxuiR April 22, 2025 at 09:17AM

No comments:

Show HN: Open-sourced my prompt management tool for LLM-powered apps https://ift.tt/4vClhqD

Show HN: Open-sourced my prompt management tool for LLM-powered apps https://ift.tt/9wY0mk7 August 3, 2025 at 01:42AM