You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
interface does not satisfy the constraint FieldValues #2
Hey @kkharji, thank you for using Modular Forms! That means a lot to me. I am aware of this problem. If you use a type instead of an interface, it works.
The problem is that a form can be nested arbitrarily and I use a recursive type for that. Why TypeScript doesn't then accept an interface as generic, I don't know yet. If you are familiar with TypeScript, you can try to help me here. Otherwise I will ask for advice in the SolidJS community.
As described in this issue, the "problem" has existed in TypeScript for a very long time now. I am not yet aware of a user-friendly workaround that does not compromise type safety. I will let you know as soon as I find a solution.
Until TypeScript gives us a "better" solution, I recommend using type instead of interface. As an alternative, the workaround of giving an interface an explicit index signature can be used. Below are two examples.
This may affect the editor support, so that e.g. autocomplete works only conditionally.
If someone here knows TypeScript very well and thinks he or she can solve the problem by making changes to Modular Forms, I have prepared a minimal TypeScript playground for experimenting. I'm temporarily closing the issue until there are signs that changes to our code can fix the problem.
I force to use interfaces with "@typescript-eslint/consistent-type-definitions": "error" and extends Record<string, string> doesn't work with boolean fields for example, so it's better to use something like this:
All solutions I know so far to be able to support interfaces reduce type safety. I have again experimented a bit, but have not come to a satisfactory solution.
Activity
fabian-hiller commentedon Nov 13, 2022
Hey @kkharji, thank you for using Modular Forms! That means a lot to me. I am aware of this problem. If you use a
typeinstead of aninterface, it works.The problem is that a form can be nested arbitrarily and I use a recursive type for that. Why TypeScript doesn't then accept an interface as generic, I don't know yet. If you are familiar with TypeScript, you can try to help me here. Otherwise I will ask for advice in the SolidJS community.
kkharji commentedon Nov 13, 2022
Oh that sucks, I was hoping it was unknown issue. Yes, typescript advance type is hard to get right, let alone supporting
interfacekeyword.No issues hopefully the rspc generator would be able to generate with
typekeyword.Thanks @fabian-hiller
fabian-hiller commentedon Nov 13, 2022
I am sure there is a solution to this problem. I will try to fix it tomorrow. I will give you an update here.
fabian-hiller commentedon Nov 13, 2022
As described in this issue, the "problem" has existed in TypeScript for a very long time now. I am not yet aware of a user-friendly workaround that does not compromise type safety. I will let you know as soon as I find a solution.
fabian-hiller commentedon Nov 20, 2022
Until TypeScript gives us a "better" solution, I recommend using
typeinstead ofinterface. As an alternative, the workaround of giving an interface an explicit index signature can be used. Below are two examples.This may affect the editor support, so that e.g. autocomplete works only conditionally.
If someone here knows TypeScript very well and thinks he or she can solve the problem by making changes to Modular Forms, I have prepared a minimal TypeScript playground for experimenting. I'm temporarily closing the issue until there are signs that changes to our code can fix the problem.
vchirikov commentedon Apr 6, 2023
I force to use interfaces with
"@typescript-eslint/consistent-type-definitions": "error"andextends Record<string, string>doesn't work with boolean fields for example, so it's better to use something like this:fabian-hiller commentedon May 7, 2023
All solutions I know so far to be able to support interfaces reduce type safety. I have again experimented a bit, but have not come to a satisfactory solution.