how do you add a property to an existing type in typescript?

Intersection Type

In typescript, If you want to add members, you can use an intersection type:

type DateWithNewMember <T> = Partial<T>
   & { newMember: boolean }

Then use like this:

dates: DateWithNewMember<Date>[];

Union Type

You could use Union type:

class newDateClass {
   readonly fullYearUTC: number;
}

Then use like this:

date: Date | newDateClass

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)