minami
minami

Reputation: 237

What is the proper typescript type for creating element

What would the return type be here?

the paths value is a function that returns an element.

export type iconName = "logo";

type icon = {
    viewBox: string;
    paths: () => ??;
};

const IconSet: Record<iconName, icon> = {
    logo: {
        viewBox: "0 0 20 20",
        paths: () => (<div>...</div>),
    },
};

export { IconSet };

I just want to use it like this in js


export const test = {
  a : () => {return (
    <div>...</div>
    
  )}
}

my package.json file

enter image description here

and tsconfig file here

enter image description here

Upvotes: 0

Views: 52

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249746

You can return JSX.Element from e function that return a JSX element:

type icon = {
    viewBox: string;
    paths: () => JSX.Element;
};

const IconSet: Record<iconName, icon> = {
    logo: {
        viewBox: "0 0 20 20",
        paths: () => (<div>...</div>),
    },
};

Playground Link

Upvotes: 1

Related Questions