I have a piece of TypeScript code that I'm having trouble to understand. I am fairly new to TypeScript.
export const TerminalWidgetOptions = Symbol("TerminalWidgetOptions");
export interface TerminalWidgetOptions {
endpoint: Endpoint.Options,
id: string,
caption: string,
label: string
destroyTermOnClose: boolean
}
Could someone tell me what exactly happens in the above code? What I do understand is that an interface of the name TerminalWidgetOptions
is created and it forces the parameters endpoint
, id
, caption
, label
and destroyTermOnClose
upon implementation into a class. I though don't quite understand the above line. So, apparently a constant is created, that can only be set once and then stays that way, right? But how can this constant have the same name as the interface type? The assignment of Symbol("TerminalWidgetOptions");
is clear. What comes from the Symbol function is put into the constant.
Is that more or less correct?
export const TerminalWidgetOptions = Symbol("TerminalWidgetOptions");
a user defined Symbol is also being created for this interface. It's a new primitive type. The OP might have misjudged it with a regular function. – Utterance