Strange class property assignment in Typescript (Javascript): '?='

Viewed 51

I've just seen the ?= assignment expression in the class property declaration.
Could someone, please, explain to me what it means?

I know about the new Optional Chaining (object?.prop) but this one is unknown for me. So I'm not sure if it's a mistake or it's a real language feature?

export class GoogleConfig {
  GOOGLE_CLIENT_ID: string
  GOOGLE_CLIENT_SECRET: string
  GOOGLE_CALLBACK_URL?='http://localhost/frontend'
  GOOGLE_CALLBACK_URL_INTERNAL?='http://localhost/auth/google'
}

Thanks for any help!

2 Answers

By default normal properties declared in interface are mandatory but you can declare a optional property with ?:.

class ShapeConfig {
    type: string;
    color?: string;
    width?: number;
}

Here, type is required, rest are optional.

It seems to be optional class property with omitted type definition

export class GoogleConfig {
  GOOGLE_CLIENT_ID: string
  GOOGLE_CLIENT_SECRET: string
  GOOGLE_CALLBACK_URL?:string ='http://localhost/frontend'
  GOOGLE_CALLBACK_URL_INTERNAL?:string ='http://localhost/auth/google'
}
Related