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

docs: update pattern matcher type #11934

Open
hyunbinseo opened this issue Mar 5, 2024 · 0 comments · May be fixed by #11935
Open

docs: update pattern matcher type #11934

hyunbinseo opened this issue Mar 5, 2024 · 0 comments · May be fixed by #11935
Labels
documentation Improvements or additions to documentation

Comments

@hyunbinseo
Copy link
Contributor

Describe the bug

Current documentation types the match as follows:

// src/params/fruit.ts

import type { ParamMatcher } from '@sveltejs/kit';

export const match: ParamMatcher = (param): param is 'apple' | 'orange' => {
  return param === 'apple' || param === 'orange';
};

This does not narrow the type beyond string.

// src/routes/archive/[page=fruit]/+page.ts

export const load = ({ params: { page } }) => {
  page; // string
};

To narrow the type - which was implemented in the following PR - the match type should be updated:

import type { ParamMatcher } from '@sveltejs/kit';

export const match = ((param): param is 'apple' | 'orange' => {
  return param === 'apple' || param === 'orange';
}) satisfies ParamMatcher;
export const load = ({ params: { page } }) => {
  page; // "apple" | "orange"
};

Reproduction

Reference the example code above.

Logs

No response

System Info

System:
  OS: macOS 14.2.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 116.55 MB / 16.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 20.11.1 - ~/.volta/tools/image/node/20.11.1/bin/node
  npm: 10.2.4 - ~/.volta/tools/image/node/20.11.1/bin/npm
  pnpm: 8.15.4 - ~/.volta/bin/pnpm
Browsers:
  Chrome: 122.0.6261.94
  Edge: 122.0.2365.63
  Safari: 17.2.1
npmPackages:
  @sveltejs/adapter-auto: ^3.0.0 => 3.1.1 
  @sveltejs/kit: ^2.0.0 => 2.5.2 
  @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.0.2 
  svelte: ^4.2.7 => 4.2.12 
  vite: ^5.0.3 => 5.1.5

Severity

annoyance

Additional Information

No response

@hyunbinseo hyunbinseo linked a pull request Mar 5, 2024 that will close this issue
6 tasks
@ghostdevv ghostdevv added the documentation Improvements or additions to documentation label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants