-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add typings #9
Add typings #9
Conversation
/cc @Rokt33r |
bbee6b6
to
775258a
Compare
📓 NOTE: this is a breaking change, type predicates require TypeScript version 3 or higher. |
The difference in use // before
if (is('heading', node)) {
const typedNode = node as Heading
// do something
}
// after
if (is<Heading>('heading', node)) {
// node is automatically type Heading within this scope
// do something
} |
This comment has been minimized.
This comment has been minimized.
typings are based off types available in definitely typed, and have been updated to add type predicate support, meaning when `unist-util-is` is used as an `if` conditional, everything inside the conditional scope can use the narrowed type. Co-authored-by: Junyoung Choi <fluke8259@gmail.com>
775258a
to
b5d7ed1
Compare
Co-authored-by: Junyoung Choi <fluke8259@gmail.com>
This comment has been minimized.
This comment has been minimized.
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.
LGTM! 😍 😍 😍
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.
One Q: is convert.d.ts
correctly picked up, when published and installed? I believe types/tsconfig.json
defines paths, but it isn’t published, and package.json
defines the main definitions only?
@wooorm I think I should try it. I'll let you know if it is good or not. |
This comment has been minimized.
This comment has been minimized.
@ChristianMurphy Error: /Users/junyoung/Code/unist-util-is/unist-util-is-test.ts:98:1
ERROR: 98:1 expect TypeScript@next: Expected an error on this line, but found none.
ERROR: 109:1 expect TypeScript@next: Expected an error on this line, but found none.
ERROR: 190:1 expect TypeScript@next: Expected an error on this line, but found none. I guess it should be better to do the test with the current local typescript installation. IMO, testing with unstable build feels a bit ridiculous. If we want to do so, we need to provide
|
Co-authored-by: Junyoung Choi <fluke8259@gmail.com>
Thanks @Rokt33r! |
This comment has been minimized.
This comment has been minimized.
@Rokt33r I tested with
|
Oddly enough, I'm also not able to reproduce the issue on the
|
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.
@ChristianMurphy It works again after I flushed ~/.dts
. Maybe the build in my mac was wrong.
It looks good to be merged now. 😄
Closes GH-9. Reviewed-by: Junyoung Choi <fluke8259@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com> Co-authored-by: Junyoung Choi <fluke8259@gmail.com>
typings are based off types available in definitely typed,
and have been updated to add type predicate support,
meaning when
unist-util-is
is used as anif
conditional, everythinginside the conditional scope can use the narrowed type.