cf.completefrontend

Predict the typesHard

Why does user.name log undefined here, when the base constructor set it?

The project compiles for ES2022, the site's default. Say every error TypeScript reports, name the type the ^? line points at, and say what the code logs when you run it.

What does TypeScript report here?
class Model {  constructor(data: object) {    Object.assign(this, data);  }} class User extends Model {  name!: string;  role = "guest";} class Admin extends Model {  declare name: string;} const user = new User({ name: "Ada", role: "admin" });console.log(user.name, user.role); const admin = new Admin({ name: "Grace" });console.log(admin.name); const name = user.name;//    ^?

Work it out first: the compiler shows every error and type.

The answer

Work out every error TypeScript reports and every type it shows, line by line. Then check.

Checking your sign-in…