```ts
export function longWord(sentence: string): string {
  if (!sentence) return '';

  const words = sentence.split(/\s+/);
  let longestWord = '';

  for (const word of words) {
    if (word.length > longestWord.length || (word.length === longestWord.length && words.indexOf(word) < words.indexOf(longestWord))) {
      longestWord = word;
    }
  }

  return longestWord;
}
```