The first part of this suggestion is about having a collection of runtime based code that still holds type safety.
The first things that comes into my mind would be some type safe ways to handle iterating over keys of an object
export function keys_of<T extends Object>(obj: T): Array<keyof T> {
return Array.from(Object.keys(obj)) as any;
}
I found that quite useful, even tho there's some unsafe part of it, like the type casting to any
Another example I have is this tool I made to leverage the Paths type of this project
I haven't put too much thoughts into it. hence why it's not type safe at the current moment,
But those functions takes time to make it in a typesafe way, hence why I suggestion making a project dedicated to that.
export function path_walker<T extends Object, P extends Paths<T>>(target: T, path: P): PathValue<T, P>{
const keys = path.split('\.')
return keys.reduce((old, curr)=>{
// @ts-expect-error
return old[curr]
}, target) as any
}
The last part of this suggestion was a bit less substantial, just that I was wondering if that would be valuable to make a project to teach people on how to make good typesafe way to code typescript.