dmv.community is one of the many independent Mastodon servers you can use to participate in the fediverse.
A small regional Mastodon instance for those in the DC, Maryland, and Virginia areas. Local news, commentary, and conversation.

Administered by:

Server stats:

165
active users

#branded

1 post1 participant1 post today

#TypeScript: Usually, structural typing is useful—objects are compatible if they have the same properties with the same types. Sometimes it isn’t—e.g:

// Old: object
const color = {
name: 'green',
};

// New: class instance
const color = new Color('green');

You can temporarily add a private property to detect where the old style is used:

class Color {
name: string;
#branded = true;
constructor(name: string) {
this.name = name;
}
}

More information: exploringjs.com/tackling-ts/ch

exploringjs.comClass-related types • Tackling TypeScript