-
-
Notifications
You must be signed in to change notification settings - Fork 13
Added extracting of templated params from params
#35
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
Conversation
package.json
Outdated
@@ -15,7 +15,7 @@ | |||
], | |||
"scripts": { | |||
"unit": "tsm node_modules/uvu/bin.js . '\\.test\\.(ts|js)$'", | |||
"test": "c8 yarn unit && eslint . && check-dts && size-limit", | |||
"test": "c8 yarn unit && eslint . --report-unused-disable-directives && check-dts && size-limit", |
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.
This change should be in different PR
@@ -24,6 +30,12 @@ interface Params { | |||
* @param input Template string. | |||
* @return Transform for translation. | |||
*/ | |||
<Input extends string>(input: Input): TranslationFunction< |
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.
In Router we were forced to define argument as const
to be sure that TS will use "/posts/:id"
type instead of just string
https://github.com/nanostores/router/blob/main/index.d.ts#L132C30-L132C35
Why we don’t need it here?
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.
Bcs in router types it's needed to narrow types for the other consumers, that will be working with returned type. Here I don't see cases why it might be necessary, but I might be wrong)
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.
I was passing by and wanted to give a hint that using canonical URLs will be safer in the future. Just press y
and the URL will become this: https://github.com/nanostores/router/blob/e927e23d509d1cde4140653071743a3c370de70b/index.d.ts#L132C30-L132C35
? { [key in Param]: string | number } & ExtractTemplateParams<Pre> & | ||
ExtractTemplateParams<Post> | ||
: {} | ||
|
||
interface Params { | ||
/** | ||
* Add `{name}` parameters to translation strings. |
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.
We will need also to change docs in TypeDoc example and in README.md
@ai wdyt about adding a case with |
Thanks. Released at 0.11. |
Close #34
Hi! This pull request solves the problem of autoinferring parameters for the
params
function, but with two edge cases:count
function, is not processed here. This requires an extension of the return type signature of theTranslationFunction
function (even if it will be readable), and will likely require updating the types of all utilities.