Is there a way to filter keys with interfaces on Typescript?

Viewed 15

Is there a way to force typescript to filter an object according to an interface?

Example here:

const myObject = { val: 1, val2: 2, val3: 3}

interface IObject {
  val: number;
  val3: number;
}

console.log(myObject as IObject)

I wanted the console.log output here to be { val:1, val3:3} but it actually includes val2 even though it is not declared on the interface, is it possible to filter this?

0 Answers
Related