#How can I valid use that satisfies operator?

2 messages · Page 1 of 1 (latest)

fervent flicker
#

Hello, I have some problem that check nullable field of class member variable.

class Parent {
  name: string;
}

class Child {
  parent?: Parent;
}

const child = new Child();
child.parent = new Parent();

// this line problem
child satisfies Omit<Child, 'parent'> & { parent: Parent };

console.log(child.parent); 

I want get non-nullable parent with child instance. But I assign concrete parent variable to child.parent but TypeScript cannot aware this assignment operation. How can I fix it?

next leaf
#

The type says it can be optional, you can assert that it's not, but that doesn't change the type information