-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Improved JSDoc comments for type correctness. #1161
Changes from all commits
adf8dd5
26ea308
e6573fa
7d21d23
b6eb3c9
1e4140a
64e8503
e95c386
d2b7141
c0ae1d4
05a7ddc
aca4d72
7f5735e
5ebff59
dd17907
0387927
3a189fa
1ed6764
37495b2
cc10b1c
6125010
972d6b3
976ac4a
78ea2ef
bce5afa
5ac7548
9f82f5b
0d2aea9
170109b
decf628
57a66e2
ab2359c
59c4695
67e5185
36f2a27
fb063cf
b479244
d4abe42
8cc588d
a2be058
bfd9743
c24eccf
09f9690
c90f388
ce26426
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
/coverage | ||
package-lock.json | ||
/test/ts/**/*.js | ||
.*.swp | ||
|
||
# Additional bundles | ||
/devtools.js | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import { IS_NON_DIMENSIONAL } from '../constants'; | ||
import options from '../options'; | ||
|
||
/** | ||
* @typedef {import('../component').Component} Component | ||
*/ | ||
|
||
/** | ||
* A DOM event listener | ||
* @typedef {(e: Event) => void} EventListner | ||
* @typedef {(e: Event) => void} EventListener | ||
*/ | ||
|
||
/** | ||
|
@@ -15,8 +19,9 @@ import options from '../options'; | |
* Properties Preact adds to elements it creates | ||
* @typedef PreactElementExtensions | ||
* @property {string} [normalizedNodeName] A normalized node name to use in diffing | ||
* @property {string} [splitText] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm aware of that. The problem is that in the cases where export function isSameNodeType(node, vnode, hydrating) {
if (typeof vnode==='string' || typeof vnode==='number') {
return node.splitText !== undefined;
}
if (typeof vnode.nodeName==='string') {
return !node._componentConstructor && isNamedNode(node, vnode.nodeName);
}
return hydrating || node._componentConstructor===vnode.nodeName;
} The above function's first argument is a node. This could be of type 1 or 3, or just a number. A type checker will look at the use of The only way to prevent these types of errors is to either escape code with [""] or do a conversion of number to string with something like: if (typeof vnode==='string' || typeof vnode==='number') {
// Manually convert numbers to string:
if (typeof node === 'number') node = node.toString()
return node.splitText !== undefined;
} This makes type checkers happy because there is no question that the value using |
||
* @property {EventListenerMap} [_listeners] A map of event listeners added by components to this DOM node | ||
* @property {import('../component').Component} [_component] The component that rendered this DOM node | ||
* @property {Component} [_component] The component that rendered this DOM node | ||
* @property {function} [_componentConstructor] The constructor of the component that rendered this DOM node | ||
*/ | ||
|
||
|
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.
ohh I like this one! Totally forgot about
typedef
👍