I've been writing tests recently in TypeScript that looked similar to this:

interface Thing {
  prop1: string;
  prop2: number;
  // ...

const thing: Thing = {
  prop1: "Hello"


Where I wanted to test a given portion of a type, but didn't care about the rest of the type (obviously the above is a very trivial example, but should illustrate the point).

As above, you can slap the @ts-ignore or new @ts-expect-error comment above the line, but this hides other potential issues and isn't really appropriate.

Partial to the Rescue

TypeScript has a great built in type of Partial<T>, that you can pass a type to and results in a type where all the properties of that type are undefined. However, you can't then use that type in place of the previous type, because it is a different type!

I created a small class, ThingFactory, that contains a set of default values. You can pass a Partial<Thing> to its make method, which merges the given properties with the default properties, and returns a "real" Thing:

class ThingFactory {
  private static readonly defaults: Thing = {
    prop1: "Hello",
    prop2: 5

  public static make(data: Partial<Thing>): Thing {
    return Object.assign({}, this.defaults, data);

From here, all you'd need to do is import the Factory, and use the make method:

import { ThingFactory } from './ThingFactory';

const t = ThingFactory.make({ prop1: "Test" });

// { "prop1": "Test", "prop2": 5 } 

As you can see, prop1 has been overwritten, but prop2 retains the default value defined in the ThingFactory.

And from there, you have a concrete object that you can use:

const thing = ThingFactory.make({ prop1: "Hello" });



I also discovered TypeScript playgrounds recently, so you can see this above code in action.