Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Result 型、自前で書くか、ライブラリ使うか

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
majimaccho
May 23, 2025
1.1k

Result 型、自前で書くか、ライブラリ使うか

TSKaigi 2025でのLT資料です

majimaccho

May 23, 2025

Transcript

17 slides
  1. 5

  2. Result 型 基本の形 type Result<T, E> = | { isOk:

    true; value: T } | { isOk: error: E, message: string }; type CreateHoge = (x: string) => Result<Hoge, HogeError>; try-catchとは違って unknownではないのでエラーの型が厳格になる エラーを発生させる可能性のある関数を明示的にできる エラー処理の抜け漏れを防ぎやすい 9