Why is this not working in TypeScript?
class Parent {
id: string = ''
}
class Child extends Parent{
name: string = ''
}
const fails: (created: Parent) => void = (created: Child) => { return };
const failsToo: ({ created }: { created: Parent }) => void = ({ created }: { created: Child }) => { return };
The error I'm encountering seems quite strange:
Type '(created: Child) => void' is not assignable to type '(created: Parent) => void'.
Types of parameters 'created' and 'created' are incompatible.
Property 'name' is missing in type 'Parent' but required in type 'Child'
It appears that it's trying to assign a Parent to a Child, however, in the actual code it's the opposite (attempting to assign a method parameter that is a Child to a Parent. This makes sense because Child is a superset of Parent)
Am I overlooking something?