lightning-js / blits

The Lightning 3 App Development Framework
Apache License 2.0
58 stars 9 forks source link

Resolve Typescript error with both Props keys #119

Closed suresh-gangumalla closed 6 days ago

suresh-gangumalla commented 6 days ago

Observed typescript error while adding normal string props and advanced props in a component props key.

Allowing only one kind of keys but not both

uguraslan commented 6 days ago

Hey @suresh-gangumalla , I tested it with the following code but I am getting an error on props property key:

export default Blits.Component('MyComp', {
  template: `
    <Element x="400" y="100" />
    `,
  props: [
    'itemA',
    'itemB',
    {
      key: 'itemC',
      required: true,
      default: 'default value',
    },
    'itemD',
  ],
  hooks: {
    ready() {},
  },
})

The error:

Type '(string | { key: string; required: true; default: string; })[]' is not assignable to type 'AdvancedProp[] | PropsArray<string>'.
  Type '(string | { key: string; required: true; default: string; })[]' is not assignable to type 'AdvancedProp[]'.
    Type 'string | { key: string; required: true; default: string; }' is not assignable to type 'AdvancedProp'.
      Type 'string' is not assignable to type 'AdvancedProp'.ts(2322)
component.d.ts(397, 5): The expected type comes from property 'props' which is declared here on type 'ComponentConfig<string, State, Methods>'
uguraslan commented 6 days ago

@suresh-gangumalla Ignore my previous comment, there was an unrelated issue with my test setup. I tested again and the fix does not have an issue.