Skip to content

How can you provide <Props> type to component in Typescript? #15

@BrianJVarley

Description

@BrianJVarley

Hey @BBKolton, I'm using this package in a React TypeScript project, so far it's been helpful to bridge the gap converting from a Custom Element to React component.

But something I'm not clear on is how you provide a concrete Props type to the reactifyWc('my-component') call.
I did see a related PR here actually to provide the Props type - #6. But in my example below the name, age props are not showing in intellisense although I've provided them in the Test interface.

Could you provide some code examples of how you attach Props to a component created with reactifyWc?
I don't see any similar examples in the README.

Below is my attempt at attaching props and resulting outcome in intellisense:

Creating Component Wrapper:

import reactifyWc from "reactify-wc";

interface Test {
  name: string;
  age: number;
}

export function createReactComponent(elementName: string) {
  return reactifyWc<Test>(elementName);
}

Result in VsCode:

Instead of picking up the Test type, the IDE is picking up the component's type as 'IntrinsicAttributes & RefAttributes<any>' somehow.

reactify-wc-prop-types-test

Type '{ name: any; age: any; }' is not assignable to type 'IntrinsicAttributes & RefAttributes<any>'.
  Property 'name' does not exist on type 'IntrinsicAttributes & RefAttributes<any>'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions