feat: narrow page param types using matchers in $app/types (non-ambient.d.ts)#15502
Conversation
🦋 Changeset detectedLatest commit: bebc152 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
elliott-with-the-longest-name-on-github
left a comment
There was a problem hiding this comment.
still going through, here are a few other comments
packages/kit/src/core/sync/write_types/test/app-types/matcher-test/no-matcher/[locale]/+page.js
Show resolved
Hide resolved
db35574 to
bcab3d4
Compare
bcab3d4 to
cadf6de
Compare
…y/kit into fix/narrow-param-types-to-matchers
|
Pushed some refactors for performance (some of the stuff we were doing was O(n^2)) and to get rid of the ts-ignores we had in there Should be good to go now, but I'll let another maintainer take a look at it since I changed a bunch of stuff Thank you! |
teemingc
left a comment
There was a problem hiding this comment.
LGTM. Just added a few comments to suggest making the if/elses easier to read
|
Thanks, @teemingc! I think you're best equipped to respond to the comments, @elliott-with-the-longest-name-on-github, but let me know if you want me to do anything :) |
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
|
@teemingc thank you! Should be addressed now |
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [@sveltejs/kit](https://svelte.dev) ([source](https://github.com/sveltejs/kit/tree/HEAD/packages/kit)) | [`2.53.4` → `2.55.0`](https://renovatebot.com/diffs/npm/@sveltejs%2fkit/2.53.4/2.55.0) |  |  | --- ### Release Notes <details> <summary>sveltejs/kit (@​sveltejs/kit)</summary> ### [`v2.55.0`](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2550) [Compare Source](https://github.com/sveltejs/kit/compare/@sveltejs/kit@2.54.0...@sveltejs/kit@2.55.0) ##### Minor Changes - feat: page and layout params with matchers are now type narrowed in `$app/types`, leading to better type safety when working with params in `$app/types`, `$app/state`, and hooks. ([#​15502](sveltejs/kit#15502)) ### [`v2.54.0`](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2540) [Compare Source](https://github.com/sveltejs/kit/compare/@sveltejs/kit@2.53.4...@sveltejs/kit@2.54.0) ##### Minor Changes - feat: allow error boundaries to catch errors on the server ([#​15308](sveltejs/kit#15308)) ##### Patch Changes - chore: upgrade `devalue` ([#​15535](sveltejs/kit#15535)) - fix: don't wait for remote functions that are not awaited in the template ([#​15280](sveltejs/kit#15280)) - feat: allow `resolve()` to accept pathnames with a search string and/or hash ([#​15458](sveltejs/kit#15458)) - chore: remove deprecation warnings for `config.kit.files.*` options when validating the Svelte config file ([#​15482](sveltejs/kit#15482)) - fix: handles form target attribute in remote form redirects ([#​15457](sveltejs/kit#15457)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My44NC4yIiwidXBkYXRlZEluVmVyIjoiNDMuODQuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Reviewed-on: https://forgejo.tail5a98.ts.net/gooilers123/monolith/pulls/45
closes #15471
Without this PR, page and layout params are always typed as
stringin$app/types,$app/state, and hooks, even when having matchers narrowing the type.If we have this matcher and a route like
src/routes/fruits/[page=fruit]:The parameter will now be typed as
'apple' | 'orange'instead ofstringin$app/types.Note that this is similar to what we already have when working with page and layout params in
src/routes/fruits/[page=fruit]/$types.jsand in load functions. The exception is that in load functions and$types.jswe know the exact route. In$app/stateand hooks we don't so all parameters will be optional and their type a union of the type of all parameters with the same name.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits