Skip to content

Commit

Permalink
fix AnyComponent with ComponentConstructor
Browse files Browse the repository at this point in the history
  • Loading branch information
scurker committed Nov 2, 2018
1 parent cd807ce commit 42c92b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/preact.d.ts
Expand Up @@ -69,7 +69,7 @@ declare namespace preact {
}

// Type alias for a component considered generally, whether stateless or stateful.
type AnyComponent<P = {}, S = {}> = FunctionalComponent<P> | Component<P, S>;
type AnyComponent<P = {}, S = {}> = FunctionalComponent<P> | ComponentConstructor<P, S>;

interface Component<P = {}, S = {}> {
componentWillMount?(): void;
Expand Down
4 changes: 4 additions & 0 deletions test/ts/VNode-test.tsx
Expand Up @@ -5,6 +5,7 @@ import {
Component,
FunctionalComponent,
ComponentConstructor,
AnyComponent
} from "../../src/preact";

class SimpleComponent extends Component<{}, {}> {
Expand All @@ -17,6 +18,9 @@ class SimpleComponent extends Component<{}, {}> {

const SimpleFunctionalComponent = () => <div />;

const a: AnyComponent = SimpleComponent;
const b: AnyComponent = SimpleFunctionalComponent;

describe("VNode", () => {
it("is returned by h", () => {
const actual = <div className="wow"/>;
Expand Down

2 comments on commit 42c92b6

@anion155
Copy link

@anion155 anion155 commented on 42c92b6 Dec 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is wrong. Cause We already have ComponentFactory. So previously there was ComponentFactory for factories, and AnyComponent for instances of Component. And now they are both the same.

@scurker
Copy link
Contributor Author

@scurker scurker commented on 42c92b6 Dec 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ComponentFactory was introduced in 8.3.0, prior to that AnyComponent was used.

See: https://github.com/developit/preact/blob/8.2.7/src/preact.d.ts#L53

With 8.3.0, AnyComponent could no longer be used for class components, so this just fixes a breaking change.

Please sign in to comment.