-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Test passing a literal object to processor.stringify #226
Conversation
The object type is correctly inferred as an mdast Root. We should make sure this doesn’t break.
This seems similar to Lines 424 to 435 in 98ab675
|
It is similar, yet very different. The tests you highlighted, assert that mdast Root satisfies the first argument of This would work too: const remarkWithStringify = unified().use(remarkStringify)
declare const value: Parameters<typeof remarkWithStringify.stringify>[0]
expectType<MdastRoot>(value) |
If you want to test that, we should probably do it in more places. A But I’m not sure it needs to be tested, here. The input of And, we have tons of tests in the Line 10 in 98ab675
|
to test assignability of a hast node, you should probably pass a valid root, with an invalid element or so inside it, and check that there’s an error on that element, which wouldn’t happen if it’s a normal unist node? |
I think to properly test it, all occurrences of
This tests the type used to properly type a plugin. It’s true that an
The tests in |
I agree we could and perhaps should test variations of literal. |
It’s tested here: Lines 432 to 434 in 98ab675
It’s also the case that your root object w/o children is both assignable to a generic unist node and a MdastRoot, and a HastRoot
Where does type inference come into play here? TS is going to assign in these cases? |
An on your earlier:
That feels very similar to these that we already have: Lines 426 to 428 in 98ab675
|
I missed this one. This pretty much asserts the same thing and convinces me this PR isn’t needed. So feel free to close.
This is ok: declare function stringify(node: import('mdast').Root): string
stringify({
type: 'root',
children: []
}) This is not ok: declare function stringify(node: import('unist').Node): string
stringify({
type: 'root',
children: [] // Type error, the `children` property is excessive
}) Also it affects editor completion, hover information, etc. |
I feel like that’s intentional, a feature not a bug, what we decided on when we removed support for arbitrary fields on |
Yes, the current behaviour a good thing. It was an answer to your question of where the type inference comes into play. |
Alright, closing! Thanks for the discussion! |
Initial checklist
Description of changes
The object type is correctly inferred as an mdast Root. We should make sure this doesn’t break.