atomicojs / atomico

Atomico a micro-library for creating webcomponents using only functions, hooks and virtual-dom.
https://atomicojs.dev
MIT License
1.15k stars 43 forks source link

TypeScript errors with 1.66.1 #100

Closed efoken closed 1 year ago

efoken commented 1 year ago

Describe the bug I'm trying to update from Atomico 1.66.0 to 1.66.1 and now getting many type errors – some are okay, some not.

Here is a simplified example from our code:

type InputProps = {
  margin?: 'normal' | 'dense' | 'none';
};

const defaultProps: Required<Pick<InputProps, 'margin'>> = {
  margin: 'normal',
};

const Input: Component<InputProps> = () => <host />;

Input.props = {
  margin: { type: String, value: defaultProps.margin },
};

The defaultProps object is coming from our shared code base – because we use them in React Native too, and we want to have shared default props between both code bases.

Before this worked fine, now we get this error:

(property) value: "dense" | "none" | "normal"
Type '"dense" | "none" | "normal"' is not assignable to type '"normal" | (() => "normal") | undefined'.ts(2322)

If I remove the InputProps from defaultProps it works, but this is not what we want, because we will loose type-safety then:

const defaultProps = {
  margin: 'normal' as const,
};

To Reproduce Steps to reproduce the behavior:

  1. Create a some component file
  2. Paste in the code I provided above
  3. See error

Expected behavior No TypeScript error.

efoken commented 1 year ago

Another one:

const CheckboxGroup: Component<{ value: string[] }> = () => <host />;

CheckboxGroup.props = {
  value: {
    type: Array,
    reflect: true, // this should work according, because Array prop is reflectable
    event: {
      type: 'change',
      bubbles: true,
    },
  },
}
Type '{ type: ArrayConstructor; reflect: true; event: { type: string; bubbles: true; }; }' is not assignable to type 'TypeAny | TypeArray<string[]>'.
  Object literal may only specify known properties, and 'reflect' does not exist in type 'SchemaArray<string[]>'.ts(2322)