-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeCompiler.Compile incorrectly parsing Record<any, any>
#916
Comments
@Lonli-Lokli Hi, sorry for the delay in reply (Have been very busy of late) TypeBox only supports a small subset of types for Record keys. These are String, Number, Boolean, TemplateLiteral and Union of Literal types. Rather than using Type.Any(), would recommend using Type.String() as it represents all permissible JSON keys (and is generally more type safe) Will close of this issue for now, but if you have any questions, feel free to ping on this thread. |
@sinclairzx81 First of all, it's not mentioned anywhere in the docs, so I wasn't ready for a production runtime error. Second, even if it's not supported why did you close this issue? Not supported !== Closed |
@Lonli-Lokli Heya,
Should TypeBox support Any for keys? It would presumably also need to support Unknown and Never keys. It's feasible for TypeBox to implement a mapping for this, however in the Any and the Unknown case, the I am open to considering this, however it would be good to get some insight into why you need Any for a Record key when String is both stricter and more correct (when considering Json validation where property keys are all string) Keep me posted. |
@sinclairzx81 Yeah, so I have cases in business Logic when keys must be a number. either direct or via enum. So for me it's easier to write parser in any |
@Lonli-Lokli Hiya, Have published an update to resolve this on 0.32.35. Record keys can now be Hope this helps |
@sinclairzx81 Thanks! Is there any way to make compilation error in this scenario? Eg in the snippet from first post, will it be possible to have an error from TypeCompiler.Compile that there is a |
@Lonli-Lokli Heya,
Never types are analogous to the TypeScript Pretty keen to keep the Never type as is; as it is a critical component of the type system. |
Incorrectly parsing Record<any, any>, while works with Record<number, string>
https://stackblitz.com/edit/vitejs-vite-1bhkml?file=counter.js&terminal=dev
The text was updated successfully, but these errors were encountered: