Skip to content

types refactoring (WIP)#3642

Closed
climba03003 wants to merge 9 commits intonextfrom
types-refactoring
Closed

types refactoring (WIP)#3642
climba03003 wants to merge 9 commits intonextfrom
types-refactoring

Conversation

@climba03003
Copy link
Copy Markdown
Member

cc @sinclairzx81
Just let you know that I am start working on refactoring the old types into a single generic param.
It will be a large change on the ecosystem and may not be doing so fast.

Checklist

@mcollina
Copy link
Copy Markdown
Member

I'm planning to start cutting v4 releases soonish. What's your ETA on finishing this work @climba03003 ?

@climba03003
Copy link
Copy Markdown
Member Author

climba03003 commented Jan 21, 2022

I'm planning to start cutting v4 releases soonish. What's your ETA on finishing this work @climba03003 ?

I assume it will be done on next week.

If it can not catch up on schedule, I am fine to go with next release.

@mcollina
Copy link
Copy Markdown
Member

no worries, I think we can wait a bit.

@mcollina mcollina added this to the v4.0.0 milestone Jan 21, 2022
@mcollina mcollina added semver-major Issue or PR that should land as semver major typescript TypeScript related labels Jan 21, 2022
@github-actions github-actions bot removed the typescript TypeScript related label Jan 24, 2022
@climba03003
Copy link
Copy Markdown
Member Author

I think most of the original types is done. Now, I am facing the issue of it breaks the TypeProvider type resolve.
@sinclairzx81 Do you have time to look at which part I am doing wrong?

@github-actions github-actions bot added the typescript TypeScript related label Jan 24, 2022
@RafaelGSS
Copy link
Copy Markdown
Member

I'm planning to look at it soon (Today or tomorrow).

@sinclairzx81
Copy link
Copy Markdown
Contributor

@climba03003 Hi, good work on the refactorings. It's a big job.

Just had a quick look at the branch. I think there could be an issue with the Schema (formally SchemaCompiler) not propagating through the types correctly. To test, I added the genericType and schemaType properties to the FastifyRequest<...> type to see what they were resolving to...as follows.

export interface FastifyRequest<
  Optional extends FastifyInstanceRouteGenericInterface = DefaultFastifyInstanceRouteGenericInterface,
  Generic extends FastifyInstanceRouteGenericInterface = OverrideRouteGeneric<Optional, DefaultFastifyInstanceRouteGenericInterface>,
  RequestType extends FastifyRequestType = ResolveFastifyRequestType<Generic>
> {
  // **added**
  genericType: Generic,
  schemaType: GetRouteSchema<Generic>

  
  id: any;
  params: RequestType['params'];
  raw: GetRequest<Generic>;
  query: RequestType['query'];
  headers: GetProp<GetRequest<Generic>, 'headers'> & RequestType['headers']; // this enables the developer to extend the 
  // ... omitted
}

Then created a implementation on the on the type provider tests to see what they were.

interface NumberProvider extends FastifyTypeProvider { output: number } // all schemas are numbers

expectAssignable(server.withTypeProvider<NumberProvider>().get(
  '/',
  {
    schema: { body: '' }
  },
  (req) => {
    const G = req.genericType // DefaultFastifyInstanceRouteGenericInterface: expected specialized interface type
    const S = req.schemaType  // FastifySchema: expected { body: '' }
  }
))

The Type Providers will need to see the schema provided by the user, however GetRouteSchema<Generic> is returning just a FastifySchema. Also the Generic argument is resolving to DefaultFastifyInstanceRouteGenericInterface (where I'd have imagined this to be generic, or mapped with the NumberProvider somewhere in its generic arguments).

There was a brief mention to the FastifySchema vs SchemaCompiler mapping requirements here #3397 (comment), but I think the trick will be ensuring that the schema appropriately gets passed through the types such that the Type Provider can see and resolve from it.

Hope that helps!

@climba03003
Copy link
Copy Markdown
Member Author

Hope that helps!

I think I will go for updating the route option and split the schema type outside of generic, then merge it back.
Your information does help on identify the what should be done next.

@climba03003
Copy link
Copy Markdown
Member Author

Here comes another problem and why it is always the default value.
Since the generic is using unknown, it is actually matching all types.
Then, if we try to override a single prop inside the generic, it will always return default.

microsoft/TypeScript#38456

@sinclairzx81
Copy link
Copy Markdown
Contributor

@climba03003 I've put together a small prototype for the object generics and taken a bit of a look at the current overloads for register(). Posting here if it's helpful for reference. This approach should help propagate those generic types downwards and support arbitrary types for the other generic parameters.

@climba03003
Copy link
Copy Markdown
Member Author

climba03003 commented Jan 26, 2022

I may not be actively fixing this in the coming few days. I have bunch of work stacked and planed to finish before the coming long holiday (of my country) in next week.

I will start the work again during weekend and next week.

@mcollina
Copy link
Copy Markdown
Member

@climba03003 any updates? I would like to ship the first rc asap.

@climba03003
Copy link
Copy Markdown
Member Author

@climba03003 any updates? I would like to ship the first rc asap.

I think you can just cut the line. I don't think it can be done in a short time based on my schedule.

@climba03003 climba03003 removed this from the v4.0.0 milestone Feb 10, 2022
@stale
Copy link
Copy Markdown

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue or pr with more than 15 days of inactivity. label Apr 16, 2022
@stale stale bot closed this Apr 27, 2022
@github-actions
Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

semver-major Issue or PR that should land as semver major stale Issue or pr with more than 15 days of inactivity. typescript TypeScript related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants