Closed kokjinsam closed 5 years ago
Thanks for the PR @sammkj .
It looks like it is missing the function definitions for intl
and withText
. Did you leave those out on purpose.
Also, I'm not super familiar with typescript, but preact defines a typings.json file and it also packages the .d.ts file as part of the build steps in package.json, which this PR doesn't do. My guess is that this PR isn't quite complete enough to have this work for the general public yet.
Build steps from preact: https://github.com/developit/preact/blob/master/package.json#L13-L14
@billneff79 , I'm not using any of those two APIs at the moment. But I can write definitions for it. Let me make some changes.
@billneff79 , I need some help here. Here's what I got so far for withText
.
// withText("foo,bar,baz")(App)
export function withText<P, S, M>(
mapping: string
): (Child: Preact.AnyComponent<P & M, S>) => Preact.FunctionalComponent<P>;
// withText(["foo", "bar", "baz"])(App)
export function withText<P, S, M>(
mapping: Array<string>
): (Child: Preact.AnyComponent<P & M, S>) => Preact.FunctionalComponent<P>;
// withText({foo: "foo", bar: "bar", baz: "baz"})(App)
export function withText<P, S, M>(
mapping: M
): (Child: Preact.AnyComponent<P & M, S>) => Preact.FunctionalComponent<P>;
usage:
class App extends Component<{ placeholder: string }, {}> {
render() {
return (
<div>
<h1>Hello</h1>
</div>
);
}
}
const Meow = withText<{}, {}, { placeholder: string }>("placeholder")(App);
But it keeps throwing the following error:
Argument of type 'typeof App' is not assignable to parameter of type 'AnyComponent<{ placeholder: string; }, {}>'.
Type 'typeof App' is not assignable to type 'ComponentConstructor<{ placeholder: string; }, {}>'.
Type 'App' is not assignable to type 'Component<{ placeholder: string; }, {}>'.
Types of property 'props' are incompatible.
Type '{ placeholder: string; } & ComponentProps<App>' is not assignable to type '{ placeholder: string; } & ComponentProps<Component<{ placeholder: string; }, {}>>'.
Type '{ placeholder: string; } & ComponentProps<App>' is not assignable to type 'ComponentProps<Component<{ placeholder: string; }, {}>>'.
Types of property 'ref' are incompatible.
Type '((el: App) => void) | undefined' is not assignable to type '((el: Component<{ placeholder: string; }, {}>) => void) | undefined'.
Type '(el: App) => void' is not assignable to type '((el: Component<{ placeholder: string; }, {}>) => void) | undefined'.
Type '(el: App) => void' is not assignable to type '(el: Component<{ placeholder: string; }, {}>) => void'.
Types of parameters 'el' and 'el' are incompatible.
Type 'Component<{ placeholder: string; }, {}>' is not assignable to type 'App'.
Types of property 'render' are incompatible.
Type '(props?: ({ placeholder: string; } & ComponentProps<Component<{ placeholder: string; }, {}>>) | u...' is not assignable to type '() => Element'.
Type 'Element | null' is not assignable to type 'Element'.
Type 'null' is not assignable to type 'Element'.
Any ideas how to solve this?
EDITS
Functional Component works with any problem. Only Class component that is causing problem.
You should either merge this or mention https://www.npmjs.com/package/@types/preact-i18n in the README 👌The latter works fine for me.
@jtrollia - I'll close this and reference the definitely typed typings
Related: #12