-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Add string literal type for router events #15497
Closed
Closed
Changes from 3 commits
Commits
Show all changes
117 commits
Select commit
Hold shift + click to select a range
8ed2aa3
Add string literal type for router events
LauraBeatris ff4171c
Accept string types for events
LauraBeatris c93b9b1
Move router event type to router
LauraBeatris 0476b70
Add generic type for mitt
timneutkens 3483e1a
Add generic for mitt event handlers
LauraBeatris 1d76bdf
Pass type for router event handler
LauraBeatris f4e0aae
Add EventMap to mitt
LauraBeatris 989b53c
Add static tweet link (#15493)
timneutkens a43cade
Upgrade cssnano-simple dependency (#15488)
Timer 46a8b4a
v9.4.5-canary.44
Timer 255bf5e
Fix peer dependency (#15511)
Timer ef2fc0d
v9.4.5-canary.45
Timer d0ddc9f
Update custom webpack config docs to mention existing features (#15517)
timneutkens ce193a9
v9.5.0
timneutkens 7bc1d5e
upgrade @ampproject/toolbox-optimizer to 2.5.14 (#15463)
sebastianbenz 4a51dfd
Update `gssp-export` Error (#15529)
Timer eb5d74e
fix typo in custom-webpack-config docs (#15533)
cvan 3f647ae
Combine sendPayload and sendHTML (#15475)
devknoll e804d5e
[update] 'yo' to 'you' (#15545)
ywppp 24eaffd
[Docs] Update links that should point to Vercel repos (#15547)
lfades edffabb
Update Apollo example for 9.5 (#15546)
0xHexE cbce43d
Update revalidate examples for 9.5 (#15551)
Timer 76bef4e
[Docs] Performance time is in milliseconds (#15544)
lfades 0982e62
De-experimentalize redirects for rosetta example (#15554)
Timer 53d67c8
Add polyfill for process and Buffer in webpack 5 (#15499)
timneutkens fef3343
improves baseUrl resolution in typescript monorepos (#13542)
jeantil 7746263
Ignore history state not created by next.js (#15379)
Janpot 826c52a
Fix: UnhandledPromiseRejectionWarning when unknown flag provided for …
darshkpatel 49f2e7f
Font optimizations (#14746)
prateekbh 10d69ea
Next.js prefetching should use requestIdleCallback (#14580)
khattakdev 625f105
Make Links rendered in the error overlay clickable [ 14017 ] (#14055)
darshkpatel f9f28cd
Add release hook to format the changelog by labels (#14592)
rafaelalmeidatk 5714d86
v9.5.1-canary.0
timneutkens dd5ef07
Update release.js and release package to avoid github rate limit (#15…
timneutkens b1fac04
Update stats-config for new polyfills location (#15584)
ijjk 0cbfb4b
fix typo in `eslint-plugin-next` code comments (#15583)
cvan 16d87a4
Update Electron, Typescript example (#15524)
laiso 074c0ca
Stabilize error-is-clickable test (#15606)
ijjk d2e4757
Make sure link can render without router (#15604)
ijjk a1ca9e3
Add better typing for redirect (#15603)
robertvansteen 0b76c4b
Update multi-zone example link from relative to absolute (#15618)
yokinist 397171c
Update header replacing to be more relaxed (#15592)
ijjk b16065f
Add note about statusCode config for redirects (#15615)
ijjk 5d77988
Fix webdriver error handling (#15491)
Janpot e0e13fd
Normalize missing optional value on Vercel (#15593)
ijjk c9a3d50
Add CSS Modules examples to docs (#15601)
lfades faf4b9b
v9.5.1-canary.1
ijjk 92e4ad0
Don't use assetprefix on getServerSideProps and getStaticProps (#15634)
Janpot 9afdb43
v9.5.1-canary.2
Timer 1766890
retry installs on macos (#15641)
Janpot 276e72d
Remove console log from release script (#15652)
rafaelalmeidatk 911572e
Test webpack 5 beta (#15645)
Timer ddbfc46
Fix: space issue in error overlay and add tests (#15617)
darshkpatel 925bffc
remove broken server example (#15653)
dd9a6f7
Fix error overlay hotlinking (#15658)
Timer 44968ad
Added docs for Incremental Static Regeneration (#15663)
lfades cb26265
v9.5.1-canary.3
Timer 2790e9d
v9.5.1
Timer e924329
Fix hot reloader edge case with broken webpack plugins (#15659)
Timer 47661ad
v9.5.2-canary.0
Timer 85038cf
Add additional pageProps check (#15667)
ijjk 1b4cdd7
Error overlay should not be dismissable for a server error (#14011)
khattakdev 15f29e8
Strictly type `react-dev-overlay` (#15669)
Timer d1d0b31
Pass RouterEventMap to mitt
LauraBeatris b74a110
Export event emitter types
LauraBeatris 2e44197
Fix type of spreaded events to emit event handler
LauraBeatris fba6400
[Examples] Fix with-sentry (#15694)
lfades 6ac4627
[Docs] Use `next dev` for the getting started page (#15705)
lfades 2c5b9c5
Docs smart-cdn link is dead. (#15707)
matamatanot 05cc0a8
Document regex support for custom routes (#15714)
ijjk 614c576
Stabilize another test (#15697)
Janpot 1936bfb
[Docs] Add upgrade notes for Next.js 9.5 (#15703)
lfades 37bfc65
Fix wrong asPath on 404 (#15728)
Janpot 0fe20fa
Update next-transpile-modules in with-react-intl example (#15730)
jonespen e4fce03
[webpack5] Complile for ES5 (#15708)
RafalFilipek 0cb7691
Update next-transpile-modules in all examples (#15739)
martpie 3e455ca
Fix gh-pages deploy script (#15724)
ronaldstevanus c31f513
Remove unused error (#15748)
Janpot d80f019
v9.5.2-canary.1
Timer 1c6a699
Fix asPath of rewrite without basePath (#15760)
Janpot d7caf50
Add clarification of routing to a dynamic route (#15771)
samrobbins85 67fdbb0
Improve router types (#15775)
Janpot 8e1bdaa
examples: Update with-electron .gitignore (#15783)
DavidLemayian 86b92e7
Remove dotenv from auth0 Next.js example (#15398)
msreekm 7a93a38
Fix dotenv loading with cascading values (#15799)
ijjk 6882447
v9.5.2-canary.2
Timer f4ae0c4
Remove implicitly any type
LauraBeatris e0fde40
Use keys of RouterHandlersMap to map router events
LauraBeatris bd27638
Add EventType type to router events
LauraBeatris acf0f77
Refactor mitt to map event handler types
LauraBeatris da435b6
Merge branch 'canary' into add-route-events-types
LauraBeatris ce7785a
Remove duplicate type
LauraBeatris 336e720
Fix mitt import and types
LauraBeatris d758284
Pass any as a generic for Emitter on ServerRouter events
LauraBeatris a9b14b5
Pass any as a generic for Emitter on page-loader events
LauraBeatris 0536b96
Merge branch 'canary' into add-route-events-types
LauraBeatris d71b882
Initialize next-server events with mitt
LauraBeatris eeabba3
Merge branch 'add-route-events-types' of https://github.com/LauraBeat…
LauraBeatris 62c44f4
Pass events directly to emit handler
LauraBeatris 172b566
Verify if event exists on mitt event
LauraBeatris f5ae8f2
Merge branch 'canary' into add-route-events-types
lfades b27c8fb
Merge branch 'canary' into add-route-events-types
LauraBeatris 00cb0e9
Rollback changes made to the mitt logic
LauraBeatris 8dd3832
Rollback changes made to router
LauraBeatris 58bd572
Merge branch 'canary' into add-route-events-types
LauraBeatris c7fe27f
Merge branch 'canary' into add-route-events-types
LauraBeatris 27e5c3e
Merge branch 'canary' into add-route-events-types
LauraBeatris 647c8f1
Merge branch 'canary' into add-route-events-types
lfades a43b2ac
Merge branch 'canary' into add-route-events-types
LauraBeatris 52b4c71
Add unit test for mitt module on typescript integration tests folder
LauraBeatris 1f362c6
Add page to test the events emitter on TS integrations folder
LauraBeatris 1c49b4b
Removed unused test
LauraBeatris 1c3e920
Improve error type for routeChangeError event
LauraBeatris bdf2220
Merge branch 'canary' into add-route-events-types
LauraBeatris 4217002
Remove unnecessary test
LauraBeatris 1cc71c3
Merge branch 'add-route-events-types' of https://github.com/LauraBeat…
LauraBeatris af88d8b
Merge branch 'canary' into add-route-events-types
LauraBeatris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this automatically inferred by typescript 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be... But I don't why the auto-completion isn't working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a look into this, the problem was that we use mitt without a generic type, so it would always be a set "string" type instead of the actual values.
I've pushed up a commit that adds a generic for mitt and then provides the values to it:
0476b70
(#15497) (thanks to @timsuchanek from Prisma who wrote the generic for mitt for me)This only solves the first parameter tbh, you could take it a bit further by adding a generic for the function itself as well. E.g. the type autocomplete could be
'routeChangeComplete', (url: string) => void
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @timneutkens, really appreciate your help 😄
Sure! I'll definitely send a commit for it
Btw, instead of repeating the same strings as in the
routerEvents
arrays just to declare aRouterEvent
literal type, wouldn't be better to create a helper function to handle this?For instance:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall that would affect bundle size in a negative way as it introduces an extra function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timneutkens Just added a generic for the event handler in 3483e1a and 1d76bdf
What do you think?