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
Types not resolving correctly after 2.9.2 #183
Comments
Hi @hamanuha and thanks for reaching out! This seems to be related to #165, you can look at https://github.com/ThomasAribart/json-schema-to-ts/blob/main/documentation/FAQs/applying-from-schema-on-generics.md This worked for me: type ContractRouteImplementation<
CONTRACT_ROUTE extends ContractRoute,
PARAMS = FromSchema<CONTRACT_ROUTE["params"]>,
QUERY = FromSchema<CONTRACT_ROUTE["query"]>,
> = () => {
handler: (request: { Params: PARAMS; Query: QUERY }) => void;
}; |
Hi @ThomasAribart, thanks for the hint. Unfortunately this does not work for me. Would you mind sharing your tsconfig? Edit: const contract = initContract({
demo: {
params: asConst({
type: 'object',
properties: {
str: { type: 'string' },
},
required: ['str'],
additionalProperties: false,
} as const),
query: externSchema,
},
}) Edit2: type ParamsFromSchema<T extends ContractRoute, TParams = Narrow<T['params']>> = TParams extends JSONSchema
? FromSchema<TParams>
: never |
Hey @ThomasAribart, did you see my second edit? |
Hi,
first of all I want to say thank you for this great library!
I use it to share typed api routes between backend and frontend.
Basically I define a contract using json schemas. This is then used for the validation and for the types on the backend and for creating the queries for the frontend.
Unfortunately upgrading to 2.12.0 or 3.0.0 breaks my code.
I heavily simplified the example below to show the issue. Some types seem to be not needed but this is due to the simplification.
If I define the schema externally for
initContract
then this works with the newer versions as well.But my inline schema for the
params
property only works with version 2.9.2.Any idea what causes this behaviour?
I would like to continue using inline schema definitions.
Types with 2.9.2
Types with 2.12.0
Simplified example
The text was updated successfully, but these errors were encountered: