0

This is my second question here so be indulgent please :).

Context : Got one Component who receive as props this , focus on resultType:

type Props = {
    //Array of an Interface populate by an import json on parent 
    arraySource: Array<{}>,

    resultType: ComponentType,

    resultStyleName: string;
    Callback: (tagsChecked : Array<string>) => void;
 };

ComponentType is a Type from React to define a Component include in framework.

So i use this to pass a type as ComponentType and use this to dynamically create component which is send to the generic component.

Then i do this and got an error on className line:

  _props.arraySource.map((propsItem) => {
      arrayTarget.push(
        <_props.resultType
          className={_props.resultStyleName}
          item={propsItem}
          Callback={propsItem}
          getCallback={getCallBackFromChild}
          >
</_props.resultType>
      );
    });

The Error is : Unable to assign type '{ className: string; item: {}; Callback: {}; getCallback: (value: any, name: string) => Promise; }' to type 'IntrinsicAttributes'. The 'className' property does not exist on the 'IntrinsicAttributes' type.ts(2322)

Was reading about Intrinsic Attributes, and understand it was a problem if we didn't define good types in Props but actually my type is define and result is good there is only this error pending

If anyone has an idea? Code is actually working and i don't want to make huge impact

  • Looks like you are accessing component that type is unknown to ts scope. I guess an dirty fix would be to cast before assignment, e.g. className={(expectedType)_props.resultStylenames}. A proper fix would be to add resultStyle to some global ts type scheme – antokhio Jul 05 '22 at 21:35
  • Try to cast it to HTMLAttributes, check that thread https://stackoverflow.com/questions/44369706/react-typescript-usage-of-classname-prop – antokhio Jul 05 '22 at 21:39
  • Or “_props.resultStylenames as ExpextedType” – antokhio Jul 05 '22 at 21:42
  • Thanks for Answering @antokhio i tried all of this answer in the link and to cast in dirty , because its generic type typescript dont recognize it, because we are in TSX – Mazout Mazout Jul 06 '22 at 09:02

0 Answers0