rdunk / sanity-blocks-vue-component

[DEPRECATED] Vue component for rendering block content from Sanity
MIT License
71 stars 10 forks source link

Example in readme doesn't typecheck #25

Open henribru opened 3 years ago

henribru commented 3 years ago

Using e.g. vue-tsc to get typechecking in Vue templates the example in the readme doesn't actually typecheck. Specifically you'll get an error that the key block is missing from the types object nested in serializers. This seems to be because block is defined as a required key here: https://github.com/rdunk/sanity-blocks-vue-component/blob/master/src/types.ts#L77. Though the serializers prop is a Partial<Serializers>, Partial doesn't extend to nested objects, so it doesn't stop block from being required.

rdunk commented 3 years ago

Perhaps I could use DeepPartial for the prop type? e.g.

type DeepPartial<T> = T extends Function
  ? T
  : T extends object
  ? { [P in keyof T]?: DeepPartial<T[P]> }
  : T;

export const SanityBlocks = defineComponent({
  ...
  props: {
    serializers: {
      type: Object as PropType<DeepPartial<Serializers>>,
      default: () => ({}),
    },
  },
  ...
});

What do you think?