Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot pass function argument to custom component #2263

Open
cpetrov opened this issue Jun 30, 2023 · 0 comments
Open

Cannot pass function argument to custom component #2263

cpetrov opened this issue Jun 30, 2023 · 0 comments
Labels

Comments

@cpetrov
Copy link
Member

cpetrov commented Jun 30, 2023

Problem description

When attempting to pass a function argument to a custom component, the TS compiler raises an error. Example:

import { contentView, Composite, Properties } from 'tabris';
import { component, property } from 'tabris-decorators';

export class App {
  public start() {
    contentView.append(
      <CustomComponent myFunctionProp={() => 'foo'} myStringProp='foo'/>,
      /**
       * Type '{ myFunctionProp: () => string; myStringProp: string; }' is not assignable to type 'JSXCompositeAttributes<CustomComponent, Widget<any>>'.
       * Property 'myFunctionProp' does not exist on type 'JSXCompositeAttributes<CustomComponent, Widget<any>>'.ts(2322)
       */
      new CustomComponent({ myFunctionProp: () => 'foo', myStringProp: 'foo' })
     /**
      * Argument of type '{ myFunctionProp: () => string; myStringProp: string; }' is not assignable to parameter of type 'Properties<CustomComponent>'.
      * Object literal may only specify known properties, and 'myFunctionProp' does not exist in type 'Properties<CustomComponent>'.ts(2345)
      */
    );
  }
}

@component
class CustomComponent extends Composite {
  @property public myFunctionProp: () => any;
  @property public myStringProp: string;

  constructor(properties: Properties<CustomComponent>) {
    super();
    this.set(properties);
  }
}

As a workaround, the jsxAttributes type can be overwritten, see https://docs.tabris.com/latest/declarative-ui.html#adding-special-attributes.

Expected behavior

One should be able to use properties with function types in custom components.

Environment

  • Tabris.js version: 3.9
@cpetrov cpetrov added the bug label Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant