Replies: 1 comment
-
Another workaround that I found is a utility type that converts creates an anonymous type based on an interface: type Primitives = string | number | boolean;
type AnonymizeProperty<T> = T extends Primitives
? T
: Anonymize<T>;
type Anonymize<T> = { [K in keyof T]: AnonymizeProperty<T[K]> }; It seems to work in my case but I haven't tested it with arrays. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am trying to use the
useSubmit
hook to submit an object and encode it asapplication/json
.Here is a small example:
submit
is typed in a way where it requires object types to have index signatures. This makes it impossible to use interfaces unless they themselves declare an index signature, because they don't have any implicitly.Type aliases or types inferred from anonymous objects do have implicit index signatures so they work.
In simple cases I can work around this by spreading
payload
into an empty object:This works because the resulting type is now
{ id: string, data: number }
which implicitly has an index signature. It stops working however if there are any properties that are typed by an interface.Is this by design? Am I doing something wrong?
Beta Was this translation helpful? Give feedback.
All reactions