pdsl
pdsl copied to clipboard
TypeScript type compilation
I think the next thing holding back this lib is the lack of automatic typescript support.
One way to manage this would be to change the way TypeScript support is provided and to create a compiler/watcher for auto compiling types to node_modules.
This would allow PDSL to be strongly typed by simply adding a unique typescript key identifier.
const isUser = p<"isUser">`{
name: string[>2],
age: > 21
}`
Behind the scenes types would be compiled to somewhere in node modules:
// node_modules/pdsl/___types.ts
export type PDSLTypes = {
isUser: { name: string, age: number }
}
The type signature of the returned function would look something like this:
type PredicateFn = <T>(input:any) => input is PDSLTypes[T]
Not sure if it is possible to maintain backward compatibility need to look up if conditionals are possible in TypeScript - I have a feeling they might be....
This would make sense to follow https://github.com/ryardley/pdsl/issues/105