Skip to content
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

set exactOptionalPropertyTypes: true, improved types #725

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

JustFly1984
Copy link

Description

Please include a summary of the change and which issue is fixed. Please also include relevant
motivation and context. List any dependencies that are required for this change.

Related #391

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • This change requires a documentation update

Screenshots/Sandbox (if appropriate/relevant):

Adding links to sandbox or providing screenshots can help us understand more about this PR and take
action on it as appropriate

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can
reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Test Environment:

  • OS:
  • package-name:
  • NodeJS:

Checklist:

  • I have followed the
    CONTRIBUTING doc and the
    style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose
the solution you did and what alternatives you considered, etc...

@JustFly1984
Copy link
Author

@ardatan please approve

@@ -35,6 +35,9 @@ describe('Fastify', () => {
url: '/mypath',
method: ['GET', 'POST', 'OPTIONS'],
handler: async (req, reply) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Types of property 'req' are incompatible.
// Type 'IncomingMessage' is missing the following properties from type 'Http2ServerRequest': authority, scheme, streamts(2345)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why we shouldn't use IncomingMessage or Http2ServerRequest interfaces directly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is falling through from const rawRequest = nodeRequest.raw || nodeRequest.req || nodeRequest;

Comment on lines +22 to +23
req?: IncomingMessage | Http2ServerRequest | undefined;
raw?: IncomingMessage | Http2ServerRequest | undefined;
Copy link
Author

@JustFly1984 JustFly1984 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ardatan This is where IncomingMessage type falls through into const rawRequest = nodeRequest.raw || nodeRequest.req || nodeRequest

@@ -84,8 +93,12 @@ export function normalizeNodeRequest(
nodeRequest: NodeRequest,
RequestCtor: typeof Request,
): Request {
// TODO: this is a main issue!
// const rawRequest: NodeRequest | IncomingMessage | Http2ServerRequest
const rawRequest = nodeRequest.raw || nodeRequest.req || nodeRequest;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const rawRequest: NodeRequest | Http2ServerRequest | IncomingMessage this is an issue, here you had created a union NodeRequest | Http2ServerRequest | IncomingMessage, and rawRequest is passed down into functions.

@JustFly1984
Copy link
Author

@ardatan can you please follow up?

@JustFly1984
Copy link
Author

@ardatan can you please follow up this week?

@ardatan
Copy link
Owner

ardatan commented Aug 7, 2023

@JustFly1984 I'll try when I am available but I cannot merge this PR like that. It needs a lot of work. Current changes break the functionality, and I don't think it is a good trade to sacrifice all these functionalities just for this TS flag.

@JustFly1984
Copy link
Author

@ardatan resolved merge conflicts

@JustFly1984
Copy link
Author

@ardatan please follow up

@JustFly1984
Copy link
Author

@ardatan please follow up. I really do not want to disable exactOptionalPropertyTypes in the project I have to use fets.

@JustFly1984
Copy link
Author

@ardatan please follow up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants