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

TypeError when optional params omitted from array #736

Open
bakerkretzmar opened this issue Mar 25, 2024 · 0 comments
Open

TypeError when optional params omitted from array #736

bakerkretzmar opened this issue Mar 25, 2024 · 0 comments

Comments

@bakerkretzmar
Copy link
Collaborator

Given this route:

const routes = {
    'posts.comments.show': {
        uri: 'posts/{post}/comments/{comment?}',
        methods: ['GET', 'HEAD'],
        parameters: ['post', 'comment'],
    },
};

Which generates these types:

interface RouteList {
    'posts.comments.show': [
        { name: 'post'; required: true },
        { name: 'comment'; required: false },
    ];
}

These valid route() calls, which should not cause any type errors, do:

route('posts.comments.show', [2]);
route('posts.comments.show', ['foo']);
route('posts.comments.show', [{ id: 2 }]);

The issue is that our type for an array of parameters doesn't specify any of them as optional (except additional unknown params after the ones we're expecting), so e.g. passing an array with less than 2 items will error if the route has 2 parameters, even if some of them are optional.

After #697 I'm hoping this will be possible to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant