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

[legacy-framework] Fix resolver.authorize( doesn't work as type guard (with great effort) #1831

Merged
merged 2 commits into from
Jan 30, 2021

Conversation

hasparus
Copy link

Closes: blitz-js/legacy-framework#411

What are the changes and their implications?

Functions in resolver.pipe can now modify the type of Ctx.

Checklist

  • Changes covered by tests (tests added if needed) — There's no way to test this automatically (yet?)
  • PR submitted to blitzjs.com for any user facing changes — not needed

I left overloads higher than n commented, because I want to discuss it.

I highly doubt anybody is going to use more than 12 function inside pipe, and you can always compose functions inside.
Each overload is slightly affecting user's TypeScript performance (as I'm too lazy to write more overloads, I'm also too lazy to back this claim with benchmarks, so you'll have to trust me :P)

}
return lastResult
}
}

interface ResolverAuthorize {
Copy link
Author

@hasparus hasparus Jan 29, 2021

Choose a reason for hiding this comment

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

I declared the type of resolver.authorize separately, because it was getting pretty complex, and while "types first, implementation later, functions as interfaces" is probably the most tiring way to write TS types, it results in the shortest error messages and tooltips

image

Choose a reason for hiding this comment

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

@hasparus Very interesting comment.

Where can I read more about the "types first, implementation later, functions as interfaces" philosophy?

I understand "types first, implementation later". But what exactly does "functions as interfaces" mean in this context? How does this fit together with the fact that PipeFn is also a function, but you defined it as type alias and not as interface?

@flybayer flybayer changed the title pipe context type through pipe chain with great effort Fix resolver.authorize( doesn't work as type guard (with great effort) Jan 30, 2021
@flybayer flybayer merged commit 89ab77a into blitz-js:canary Jan 30, 2021
@dillondotzip dillondotzip changed the title Fix resolver.authorize( doesn't work as type guard (with great effort) [legacy-framework] Fix resolver.authorize( doesn't work as type guard (with great effort) Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pipe.authorize() doesn't work as type guard
3 participants