Run ❯
Get your
own Node
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
// @ts-check /** @typedef {{ name: string, age: number }} Person */ /** @typedef {Person & { employeeId: string }} Employee */ /** @typedef {Person | { guestId: string, visitDate: Date }} Visitor */ /** @type {Employee} */ const employee = { name: 'Alice', age: 30, employeeId: 'E123' }; /** @type {Visitor} */ const guest = { guestId: 'G456', visitDate: new Date() }; /** * @param {Visitor} visitor * @returns {string} */ function getVisitorId(visitor) { if ('guestId' in visitor) { return visitor.guestId; } return visitor.name; } console.log(getVisitorId(guest));
Expected console output:
G456