-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Type 'Interface' does not satisfy the constraint 'readonly any[] | ObjectOptional'. #114
Comments
I think the essence of the error lies in the index signature part.
And the fact that interface cannot be assigned to an indexing signature is as intended by the TypeScript specification, as discussed in the following issue. I think the error can be resolved by using |
Another solution, at least as far as I have experimented, is to shallow-clone the input data, such that you are closing the type off to further augmentation. This means that typescript can then reliably infer the index signature. |
@yutak23 I'm facing the same issue and unfortunately I have no control over whether to use |
I don't know if this will work because I haven't actually tried it, but would the following method of converting to a interface ThirdPartyInterface {
hoge: string | null;
...
}
type ThirdPartyType = {
[P in keyof ThirdPartyInterface]: ThirdPartyInterface[P];
}; |
@yutak23 ah yes that works! it's a bit tedious but it solves my issue for now :). Thanks! |
I'm still using the version |
My preferred workaround (given it is an object):
|
Hey folks, I'm using yours lib to fix some third pattern response and types.
The third lib returned me an interface called
Places
, for example,import type { Places } from "@duffel/api/Places/Suggestions/SuggestionsType";
And I'm using like this:
but when I try to update from v8.0.2 to v9.0.0 I get this error (it's working on 8.0.2):
Type 'Places' does not satisfy the constraint 'readonly any[] | ObjectOptional'.
Which can be reproduced here:
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgYQIYgKYBs0GcMDSGAnrnAL5wBmUEIcA5AMbrYv4C0A1ibgwFCDgAOxgYoVVEwxwAClikYyCfnDgxQGAPoAvCMIwAuOLhhQRAczgAfOMICuWLAG5+5QTGJgZAJSWP4AF4UVhxUfCJSAB55RVwAPn4gA
and also, on the return it's not showing the correct fields.
before:
after:
How I can fix this?
The text was updated successfully, but these errors were encountered: