-
-
Notifications
You must be signed in to change notification settings - Fork 8
Update typings for convert #11
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
Typings for the convert should include `undefined` or `null`, as they are handled in the convert function.
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.
Thanks @Roang-zero1!
Could you add some typing tests, verifying how the updated Test
type impacts the is
function?
Sure. Question in that regard: |
The types are wrong. It’s useful and normal to be able to check if something is a node |
* The test parameter is optional. * Add tests for the is function.
Updated test parameter to be optional and added tests. |
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 my opinion, adding undefined
and null
to Test
type looks quite wrong. It should just define how test looks like. So other libraries like unist-util-find
don't allow null
or undefined
.
So I think we should fix argument type of the functions.
@@ -57,7 +62,7 @@ declare namespace unistUtilIs { | |||
*/ | |||
declare function unistUtilIs<T extends Node>( | |||
node: unknown, | |||
test: unistUtilIs.Test<T> | Array<unistUtilIs.Test<any>>, | |||
test?: unistUtilIs.Test<T> | Array<unistUtilIs.Test<any>>, |
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.
Should be test?: unistUtilIs.Test<T> | Array<unistUtilIs.Test<any>> | null
. And don't forget to fix convert
function too.
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 is needed only if null
and undefined
are removed from Test
correct?
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.
Yes.
I see where you're coming from on this.
do support |
|
@wooorm so do you agree with this? If so, rather than removing |
Right, yeah, the given test is optional (and null and undefined mark it as such explicitly). No test means that a test is created that checks if the later given value is a node. It’s documented here: “When not given, checks if node is a Node.” If this should be clearer, what do you suggest? |
I think the document should describe what can be a But I still think removing But the actual effect of the removing is quite limited. It is just about allowing |
All cases of the
I see it the other way around: Note: I’m not talking about typings: I’m discussing the JS library, maybe that’s why we’re missing each other’s points? |
I think so. I just want to make the types based on the document.
Yes, they are. But the document about |
How so? |
🔔 @Rokt33r |
For me, So when I read Also allowing Btw, I have another suggestion. Why don't we just make another type alias, type Test<T extends Node> =
| TestType<T>
| TestObject<T>
| TestFunction<T>
type Testable<T extends Node> = Test<T> | Array<Test<T>> | undefined | null It would save the hustle you mentioned in #11 (comment) |
🤷♂️ I see it both ways. type Test<T extends Node> =
| TestType<T>
| TestObject<T>
| TestFunction<T>
type Testable<T extends Node> = Test<T> | Array<Test<T>> | undefined | null
It would reduce the hustle, but we'd still need to go to each package and update Another idea, Thoughts? 💭 |
Hmm I'm also thinking that we cannot justify avoiding the hustle if there are some better ways to do. Anyway, let's try to find a consensus first. Once it is determined and is required more hustles or less, I would gladly do.
Using Anyway, the only problem I do have is that we didn't define what But I'm sure we don't expect users to use Maybe we should not use So it should be like test?: TestType<T>
| TestObject<T>
| TestFunction<T>
| null
| Array<unistUtilIs.Test<any>> Otherwise, we should update our documentation like below
Then we can definitely include nully values to |
This seems to have stalled, and I’m not how to continue this? |
@wooorm Sorry for my late answer. I'm still thinking that we should not include |
cc/ @ChristianMurphy, what about you? I mainly want to resolve this. Either docs, or types, or whatnot. |
#11 (comment) still summarizes my thoughts on this. |
Put another way, if we add |
Thanks @Roang-zero1 for your patience. I believe adding this, plus the note I added to the docs, makes the types, docs, and actual implementation, as close to each other as possible, and as explicit as can be without breaking everything. |
The current typings for the convert function argument do not include
undefined
ornull
, even though these cases are handled.Adding these types would allow users to not implement additional checks, but let unist-util-is handle the verification.