-
Notifications
You must be signed in to change notification settings - Fork 53
fix: types node16 resolution #117
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
Changes from 2 commits
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 |
---|---|---|
@@ -1,11 +1,4 @@ | ||
import { h, AnyComponent } from 'preact'; | ||
|
||
type PreactCustomElement = HTMLElement & { | ||
_root: ShadowRoot | HTMLElement; | ||
_vdomComponent: AnyComponent; | ||
_vdom: ReturnType<typeof h> | null; | ||
_props: Record<string, unknown>; | ||
}; | ||
import { AnyComponent } from 'preact'; | ||
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. No longer a module file, had to move this out |
||
|
||
type Options = | ||
| { | ||
|
@@ -46,9 +39,11 @@ type Options = | |
* const klass = register(PreactComponent, 'my-component'); | ||
* ``` | ||
*/ | ||
export default function register<P = {}, S = {}>( | ||
declare function register<P = {}, S = {}>( | ||
Component: AnyComponent<P, S>, | ||
tagName?: string, | ||
propNames?: (keyof P)[], | ||
options?: Options | ||
): HTMLElement; | ||
|
||
export = register; | ||
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. Actual fix |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import { h, cloneElement, render, hydrate, Fragment } from 'preact'; | ||
|
||
/** | ||
* @typedef {import('./index.d.ts').PreactCustomElement} PreactCustomElement | ||
* @typedef {import('./internal.d.ts').PreactCustomElement} PreactCustomElement | ||
*/ | ||
|
||
/** | ||
* @type {import('./index.d.ts').default} | ||
* @type {import('./index.d.ts')} | ||
*/ | ||
export default function register(Component, tagName, propNames, options) { | ||
function PreactElement() { | ||
const inst = /** @type {PreactCustomElement} */ ( | ||
Reflect.construct(HTMLElement, [], PreactElement) | ||
); | ||
inst._vdomComponent = Component; | ||
inst._root = | ||
options && options.shadow | ||
? inst.attachShadow({ mode: options.mode || 'open' }) | ||
: inst; | ||
|
||
if (options && options.adoptedStyleSheets) { | ||
inst._root.adoptedStyleSheets = options.adoptedStyleSheets; | ||
if (options && options.shadow) { | ||
inst._root = inst.attachShadow({ mode: options.mode || 'open' }); | ||
|
||
if (options.adoptedStyleSheets) { | ||
inst._root.adoptedStyleSheets = options.adoptedStyleSheets; | ||
} | ||
} else { | ||
inst._root = inst; | ||
Comment on lines
-16
to
+24
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. Drive-by, TS complains that |
||
} | ||
|
||
return inst; | ||
|
@@ -49,9 +51,7 @@ export default function register(Component, tagName, propNames, options) { | |
propNames.forEach((name) => { | ||
Object.defineProperty(PreactElement.prototype, name, { | ||
get() { | ||
return this._vdom | ||
? this._vdom.props[name] | ||
: this._props[name]; | ||
return this._vdom ? this._vdom.props[name] : this._props[name]; | ||
}, | ||
set(v) { | ||
if (this._vdom) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { h, AnyComponent } from 'preact'; | ||
|
||
export type PreactCustomElement = HTMLElement & { | ||
_root: ShadowRoot | HTMLElement; | ||
_vdomComponent: AnyComponent; | ||
_vdom: ReturnType<typeof h> | null; | ||
_props: Record<string, unknown>; | ||
}; |
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.
ESLint fails if it can't find a single matching file & we have no
.jsx
files insrc/
.