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

Move props option to second arg of createRoute utility #421

Merged
merged 24 commits into from
Jan 15, 2025

Conversation

pleek91
Copy link
Contributor

@pleek91 pleek91 commented Jan 12, 2025

Description

By moving the props option of createRoute to the second argument we can get much better typescript support and typescript errors. The utility will now correctly error when props are missing entirely if it detects the component has props that are required. And if the return type from the props function doesn't match the expected type for a component it gives much better errors.

const route = createRoute({
  ...
  component: echo,
}, () => ({
  value: 'hello world',
}))

Routes with named views will also expect an object by the same keys

const route = createRoute({
  ...
  components: {
    default: echo
  }
}, {
  default: () => ({ value: 'hello world' })
})

@pleek91 pleek91 marked this pull request as draft January 12, 2025 05:25
Copy link

netlify bot commented Jan 12, 2025

Deploy Preview for kitbag-router ready!

Name Link
🔨 Latest commit 6a29a8d
🔍 Latest deploy log https://app.netlify.com/sites/kitbag-router/deploys/67871401ef87220008897f04
😎 Deploy Preview https://deploy-preview-421--kitbag-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@stackoverfloweth stackoverfloweth left a comment

Choose a reason for hiding this comment

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

looking great, I got it building (committed) and fixed all the tests that relied on props (also committed)

src/types/route.ts Outdated Show resolved Hide resolved
@pleek91 pleek91 force-pushed the create-route-type-refactor branch from 6ad8fc3 to 8b20533 Compare January 12, 2025 20:42
@pleek91 pleek91 marked this pull request as ready for review January 15, 2025 01:50
@pleek91 pleek91 changed the title WIP: Move props option to second arg of createRoute utility Move props option to second arg of createRoute utility Jan 15, 2025
Copy link
Contributor

@stackoverfloweth stackoverfloweth left a comment

Choose a reason for hiding this comment

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

🚢 IT

Copy link
Contributor

Choose a reason for hiding this comment

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

so much simpler! 😍

@pleek91 pleek91 merged commit fb63e3a into main Jan 15, 2025
6 checks passed
@pleek91 pleek91 deleted the create-route-type-refactor branch January 15, 2025 02:02
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