const v = getNumberOrString() as string; console.log(v.slice(0, 10)); function getNumberOrString(): number | string { return Math.random() ? "foo" : 123; } number | string㘗ך䒭 string㘗חتٍؐٝؗأز
function getAnchorOfNode(node: HTMLElement): HTMLAnchorElement | null { let current: HTMLElement | null = node; while (current) { if (current.tagName === "A") { return current as HTMLAnchorElement; } current = current.parentNode as HTMLElement | null; } return null; }
㢌侧ח㎳⥂㶷׃זְ function getAnchorOfNode(node: HTMLElement): HTMLAnchorElement | null { let current: HTMLElement | null = node; while (current) { if (current.tagName === "A") { return current as HTMLAnchorElement; } current = current.parentNode as HTMLElement | null; } return null; }