Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
interface を活用して安全性と拡張性を兼ね備えた型を作る
Search
all-user
November 26, 2024
Programming
0
74
interface を活用して安全性と拡張性を兼ね備えた型を作る
2024/11/16 TSKaigi KansaiのLTで使用した資料です!
https://kansai.tskaigi.org/talks/all-user
all-user
November 26, 2024
Tweet
Share
Other Decks in Programming
See All in Programming
Ruby on cygwin 2025-02
fd0
0
140
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
150
Honoのおもしろいミドルウェアをみてみよう
yusukebe
1
200
Honoをフロントエンドで使う 3つのやり方
yusukebe
7
3.1k
SwiftUIで単方向アーキテクチャを導入して得られた成果
takuyaosawa
0
270
Immutable ActiveRecord
megane42
0
140
ソフトウェアエンジニアの成長
masuda220
PRO
10
920
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
130
[JAWS-UG横浜 #80] うわっ…今年のServerless アップデート、少なすぎ…?
maroon1st
1
180
SRE、開発、QAが協業して挑んだリリースプロセス改革@SRE Kaigi 2025
nealle
3
4.2k
ペアーズでの、Langfuseを中心とした評価ドリブンなリリースサイクルのご紹介
fukubaka0825
2
310
Unity Android XR入門
sakutama_11
0
150
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
550
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.8k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Adopting Sorbet at Scale
ufuk
74
9.2k
Building Adaptive Systems
keathley
40
2.4k
Side Projects
sachag
452
42k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Docker and Python
trallard
44
3.3k
Navigating Team Friction
lara
183
15k
Transcript
© Techtouch, Inc. JOUFSGBDFΛ׆༻ͯ͠ ҆શੑͱ֦ுੑΛ݉Ͷඋ͑ͨܕΛ࡞Δ 2024/11/16 Ԭຊ ܓଠ@all-user
© Techtouch, Inc. ࣗݾհ 2 ຊ໊ɿԬຊܓଠ (JU)VCɿ!BMMVTFS 5XJUUFSɿ!BMM@@VTFS wςοΫλονגࣜձࣾͰ%0.पΓͷ։ൃΛߦ͏ &MFNFOUνʔϜͷϑϩϯτΤϯυ
wिۙ͘ͷߴඌࢁʹΑ͘ొͬͯ·͢ wӡ͕͍͍ͱ࢜ࢁ͕ݟ͑·͢
© Techtouch, Inc. 3 ΫϩευϝΠϯJGSBNFؒͷϝοηʔδϯάػೳͷ࣮Λ௨ͯ͡ɺ JOUFSGBDFͷએݴϚʔδΛ׆༻ͨ͠ࣄྫΛ͝հ͠·͢
© Techtouch, Inc. 4 ςοΫλονը໘্ʹૢ࡞ΨΠυπʔϧνοϓΛ ؆୯ʹஔ͢Δ͜ͱ͕Ͱ͖ΔϊʔίʔυπʔϧͰ͢
© Techtouch, Inc. 5 ܦඅਃͳͲͨ·ʹ͔͠Θͳ͍γεςϜͷ͍ํ͕ ͔Βͳ͍ɺɺɺͱ͍͏ܦݧΛ͞Εͨ͜ͱ Ұ͋ΔͷͰͳ͍Ͱ͠ΐ͏͔ʁ
© Techtouch, Inc. 6 ͦΜͳ࣌ʹ͜ͷΑ͏ͳऍ͕͋Ε ໎͏͜ͱͳ͘γεςϜΛར༻Ͱ͖·͢ ۭ͜͜ཝͰ0,ʂ ͔Βͳ͍࣌ ʮ99ʯΛબ
© Techtouch, Inc. 7 ΫϩευϝΠϯJGSBNFʹରԠ͍ͯ͠·͢ɻ ʢҰ෦ະରԠ͋Γʣ ۭ͜͜ཝͰ0,ʂ ͔Βͳ͍࣌ ʮ99ʯΛબ
© Techtouch, Inc. 8 ΫϩευϝΠϯJGSBNFͷ෦ʹ XJOEPX͔Β+4ͰΞΫηε͢Δ͜ͱ͕Ͱ͖ͳ͍ʂ
© Techtouch, Inc. 9 ϝοηʔδϯά͠·͢
© Techtouch, Inc. 10 ΫϩευϝΠϯJGSBNFͱͷ௨৴ػೳΛ ϥΠϒϥϦͱ࣮ͯ͢͠Δ
© Techtouch, Inc. 11 ϝοηʔδͷܕΛͲͷΑ͏ʹදݱ͢Δ͔ // ϥΠϒϥϦଆ: @tt/messaging export type
Message = { type: string; // ܕ҆શੑ͕ࣦΘΕΔ payload: any; // ܕ҆શੑ͕ࣦΘΕΔ }; const createMessaging = () => { return { postMessage(type: string, payload: any) { // ࣮ }, }; };
© Techtouch, Inc. 12 ۩ମతͳ༻్ΞϓϦέʔγϣϯଆ͔͠Βͳ͍ͷͰ େ·͔ͳܕ͔͠ఆٛ͢Δ͜ͱ͕Ͱ͖ͳ͍ɻ // ϥΠϒϥϦଆ: @tt/messaging export
type Message = { type: string; // ܕ҆શੑ͕ࣦΘΕΔ payload: any; // ܕ҆શੑ͕ࣦΘΕΔ }; const createMessaging = () => { return { postMessage(type: string, payload: any) { // ࣮ }, }; };
© Techtouch, Inc. 13 // ϥΠϒϥϦଆ: @tt/messaging export type Message
= | { type: "scrollTo"; payload: { x: number; y: number; }; } | { type: "dispatchInput"; payload: { value: string; }; } const createMessaging = () => { return { send<Msg extends Message>(type: Msg["type"], payload: Msg["payload"]) { // ࣮ }, }; }; ͡Ό͋ϥΠϒϥϦଆʹશ෦ॻ͍ͪΌ͓͏
© Techtouch, Inc. 14 // ϥΠϒϥϦଆ: @tt/messaging export type Message
= | { type: "scrollTo"; payload: { x: number; y: number; }; } | { type: "dispatchInput"; payload: { value: string; }; } | { type: "getBoundingClientRect"; payload: { selector: string; }; }; const createMessaging = () => { return { send<Msg extends Message>(type: Msg["type"], payload: Msg["payload"]) { // ࣮ }, }; }; ΞϓϦέʔγϣϯଆͰͷ༻్͕૿͑Δͨͼʹ ϥΠϒϥϦଆʹखΛՃ͑Δඞཁ͕͋Δ
© Techtouch, Inc. 15 // ϥΠϒϥϦଆ: @tt/messaging export type Message
= | { type: "scrollTo"; payload: { x: number; y: number; }; } | { type: "dispatchInput"; payload: { value: string; }; } | { type: "getBoundingClientRect"; payload: { selector: string; }; }; const createMessaging = () => { return { send<Msg extends Message>(type: Msg["type"], payload: Msg["payload"]) { // ࣮ }, }; }; ผͷΞϓϦέʔγϣϯͰར༻͢Δͱ͍ͬͨ ࠶ར༻ੑ٘ਜ਼ʹͳͬͯ͠·͏
© Techtouch, Inc. 16 ܕ҆શੑͱ֦ுੑͷͲͪΒ͔Λ ఘΊΔ͜ͱʹͳͬͯ͠·͏ɻɻɻ
© Techtouch, Inc. 17 Ͳ͏ʹ্͔ख͍͜ͱͰ͖ͳ͍͔ɺɺɺ
© Techtouch, Inc. 18 ͦ͏͍͑.6*ͷ 5IFNJOHͬͯJOUFSGBDFΛͬͯͨͳ
© Techtouch, Inc. 19 declare module '@mui/material/styles' { interface Theme
{ status: { danger: string; }; } // allow configuration using `createTheme()` interface ThemeOptions { status?: { danger?: string; }; } } 5IFNF5IFNF0QUJPOTͷܕΛ ͋ͱ͔Β֦ுͰ͖Δ
© Techtouch, Inc. 20 ͜ΕΛ͍ͬͯ͘ʂ
© Techtouch, Inc. 21 // ϥΠϒϥϦଆ: @tt/messaging export interface MessageMap
{ // ϥΠϒϥϦଆͰԿఆٛ͠ͳ͍ } const createMessaging = () => { return { send<T extends keyof MessageMap>(type: T, payload: MessageMap[T]) { // ࣮ }, }; }; ϥΠϒϥϦଆͰඞཁ࠷ݶͷఆٛͷΈ
© Techtouch, Inc. 22 // ϥΠϒϥϦଆ: @tt/messaging export interface MessageMap
{ // ϥΠϒϥϦଆͰԿఆٛ͠ͳ͍ } const createMessaging = () => { return { send<T extends keyof MessageMap>(type: T, payload: MessageMap[T]) { // ࣮ }, }; }; // ΞϓϦέʔγϣϯଆ: app.ts declare module "@tt/messaging" { interface MessageMap { scrollTo: { x: number; y: number; }; } } const messaging = createMessaging(); messaging.send("scrollTo", { x: 10, y: 42, }); // ✅ ܕ҆શ ΞϓϦέʔγϣϯଆͰ ༻్ʹԠͨ͡ϝοηʔδͷܕΛఆٛ ϥΠϒϥϦଆͰඞཁ࠷ݶͷఆٛͷΈ
© Techtouch, Inc. 23 JOUFSGBDFͷએݴԿͰখ͚ʹߦ͏͜ͱ͕Ͱ͖Δ
© Techtouch, Inc. 24 ΞϓϦέʔγϣϯଆͰ͜ΕΒͷએݴΛ ҰՕॴʹ·ͱΊͯهड़͢Δඞཁͳ͍ declare module "@tt/messaging" {
interface MessageMap { scrollTo: { x: number; y: number; }; } interface MessageMap { dispatchInput: { value: string; }; } interface MessageMap { getBoundingClientRect: { selector: string; }; } }
© Techtouch, Inc. 25 ͦͷͨΊɺΞϓϦέʔγϣϯଆͰ͜ΕΒͷએݴΛ ҰՕॴʹ·ͱΊͯهड़͢Δඞཁͳ͍ declare module "@tt/messaging" {
interface MessageMap { scrollTo: { x: number; y: number; }; } } declare module "@tt/messaging" { interface MessageMap { dispatchInput: { value: string; }; } } declare module "@tt/messaging" { interface MessageMap { getBoundingClientRect: { selector: string; }; } }
© Techtouch, Inc. 26 ؔ࿈͢Δ࣮ͷ͙ۙ͘͢Ͱએݴ ϘτϜΞοϓʹܕΛఆٛ declare module "@tt/messaging" {
interface MessageMap { scrollTo: { x: number; y: number; }; } } declare module "@tt/messaging" { interface MessageMap { dispatchInput: { value: string; }; } } declare module "@tt/messaging" { interface MessageMap { getBoundingClientRect: { selector: string; }; } }
© Techtouch, Inc. 27 // ΞϓϦέʔγϣϯଆ: iframeScript.ts import { scrollTo
} from "./PATH_TO/scrollTo.ts"; import { dispatchInput } from "./PATH_TO/dispatchInput.ts"; import { getBoundingClientRect } from "./PATH_TO/getBoundingClientRect.ts"; export const iframeImplements = { scrollTo, dispatchInput, getBoundingClientRect, } satisfies Record<keyof MessageMap, unknown>; એݴϚʔδ͞Εͨ࠷ऴతͳܕΛར༻ͯ͠ ܕνΣοΫΛߦ͏
© Techtouch, Inc. 28 એݴϚʔδ͞Εͨ࠷ऴతͳܕΛར༻ͯ͠ ܕνΣοΫΛߦ͏ // ΞϓϦέʔγϣϯଆ: iframeScript.ts import
{ scrollTo } from "./PATH_TO/scrollTo.ts"; import { dispatchInput } from "./PATH_TO/dispatchInput.ts"; // import { getBoundingClientRect } from "./PATH_TO/getBoundingClientRect.ts"; export const iframeImplements = { scrollTo, dispatchInput, // getBoundingClientRect, // ^ ΈࠐΉͷΛΕͯ͠·ͬͨɺɺɺ } satisfies Record<keyof MessageMap, unknown>; // ❌ શͯͷϓϩύςΟ͕ἧ͍ͬͯΔ͜ͱΛݕࠪͰ͖Δ
© Techtouch, Inc. 29 ҙ
© Techtouch, Inc. 30 74$PEF্ͷܕνΣοΫͷද͕ࣔ UTDͷܕνΣοΫͷ݁ՌͱҟͳΔ߹͕͋Δ
© Techtouch, Inc. 31 74$PEF্ͰΤϥʔͷදࣔͰ
© Techtouch, Inc. 32 Ϗϧυ࣌ͷܕνΣοΫ௨Δ
© Techtouch, Inc. 33 wςοΫλονϞϊϨϙߏͰ wΤϯτϦϙΠϯτʢUTDPOGJHKTPOʣ͕ෳ͋Γ wએݴϚʔδ͞ΕΔܕ͕ΤϯτϦϙΠϯτ͝ͱʹҟͳΔ
© Techtouch, Inc. 34 74$PEFͰUTDPOGJHKTPO͕ෳ͋ͬͨ߹ʹɺ ͲͷUTDPOGJHKTPOʹج͍ͮͯܕνΣοΫ͢Εྑ͍͔ அͰ͖ͳ͍ͷͰͳ͍͔ʁ
© Techtouch, Inc. 35 ͦΜͳ͜ͱͳ͔ͬͨ
© Techtouch, Inc. 36 w ࠷খߏͰ࠶ݱڥΛࢼΈ͕ͨಉ͡ى͖ͳ͍ w 74$PEFෳͷUTDPOGJHKTPO͕͋ͬͯɺదͳUTDPOGJHKTPO ʹج͍ͮͯܕʹղܾͯ͘͠Εͨʢ͍͢͝ʣ
© Techtouch, Inc. 37 w ͳͷͰ·ͩ࠶ݱ݅Θ͔ͬͯͳ͍Ͱ͢ w ϞϊϨϙߏͷن͕େ͖͍ͱղܾ͢ΔએݴϚʔδͷ͕ଟ͘ͳΓɺҰ ఆͷΛ͑Δͱ࠶ݱ͢Δͷ͔͠Εͳ͍
© Techtouch, Inc. 38 ·ͱΊ
© Techtouch, Inc. 39 w ܕ҆શੑͱ֦ுੑͷཱ͕྆Մೳ w ϥΠϒϥϦͱΞϓϦέʔγϣϯؒͷॊೈͳܕఆٛΛ࣮ݱ w ϘτϜΞοϓͳܕఆٛͰϝϯςφϯεੑͷߴ͍ίʔυΛ࣮ݱ
JOUFSGBDFͷએݴϚʔδΛ׆༻͢Δ͜ͱͰ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂʂʂ
ͯ͢ͷϢʔβʔ͕ γεςϜΛ͍͜ͳͤΔੈքʹ γεςϜಋೖ͚ͩͰऴΘΒͤͳ͍ɺར׆༻ͷͨΊͷDXϓϥοτϑΥʔϜ
None