hybridsjs / hybrids

Extraordinary JavaScript UI framework with unique declarative and functional architecture
https://hybrids.js.org
MIT License
3.03k stars 85 forks source link

"children" fabric causes TypeScript error #238

Closed Qsppl closed 5 months ago

Qsppl commented 5 months ago
import { children, define } from "https://esm.sh/hybrids@8.2.11"

export interface IFirstComponent extends HTMLElement {
    prop2: number
}

const FirstComponent = define<IFirstComponent>({
    tag: "a-first",
    prop2: 0
})

export interface ISecondComponent extends HTMLElement {
    prop1: number
    childСomponents: IFirstComponent[]
}

export default define<ISecondComponent>({
    tag: "a-second",
    prop1: 0,
    childСomponents: children(FirstComponent)
})

image

message:

Type 'Descriptor<ISecondComponent, IFirstComponent>' is not assignable to type 'Property<ISecondComponent, IFirstComponent[]>'.
  Type 'Descriptor<ISecondComponent, IFirstComponent>' is not assignable to type 'Descriptor<ISecondComponent, IFirstComponent[]>'.
    Types of property 'value' are incompatible.
      Type 'IFirstComponent | undefined' is not assignable to type 'IFirstComponent[] | undefined'.
        Type 'IFirstComponent' is not assignable to type 'IFirstComponent[]'.

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "strict": true,
    "baseUrl": "./web",
    "paths": {
      // "/" is not "C:/", but is "./web"
      "/*": [ "*" ],
      // from module to their declaration
      "/modules/fingerprintjsv3.js": ["../node_modules/@fingerprintjs/fingerprintjs/dist/fp"],
      "https://esm.sh/mitt@3.0.1": ["../node_modules/mitt/index"],
      "https://esm.sh/just-intersect@4.3.0": [ "../node_modules/just-intersect/index" ],
      "https://esm.sh/bootstrap@5.3.2": ["../node_modules/@types/bootstrap/index"],
      "https://esm.sh/hybrids@8.2.11": ["@types/hybrids"],
      "https://esm.sh/colorjs.io@0.4.5": ["../node_modules/colorjs.io/types/src/index"],
      "https://esm.sh/ts-debounce@4.0.0": ["../node_modules/ts-debounce/dist/src/index"],
      "https://esm.sh/mezr@1.1.0": ["../node_modules/mezr/dist/esm/index"]
    },
    "skipLibCheck": true
  },
  "include": [ "./web" ]
}

typescript version: "5.1.6"

smalluban commented 5 months ago

I don't have time to check every TS error (from all of your issues) - can you confirm if the problem is solved by using TS v4?

FYI: https://github.com/hybridsjs/hybrids/issues/236#issuecomment-2009222885

Qsppl commented 5 months ago

Typescript version: 4.9.5 did not solve these problems. This appears to be a typo in the types.

smalluban commented 5 months ago

You're right, fixed in https://github.com/hybridsjs/hybrids/commit/f29902f042995f1aa76f9d7cc5cf28e9e4a915a1

I'll wait for the bumping version until tomorrow if there will be other things related to TS.

Qsppl commented 5 months ago

Thanks, this solved the problem