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
120
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
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
410
Ruby Parser progress report 2025
yui_knk
1
460
OSS開発者という働き方
andpad
5
1.7k
GitHubとGitLabとAWS CodePipelineでCI/CDを組み比べてみた
satoshi256kbyte
4
250
CJK and Unicode From a PHP Committer
youkidearitai
PRO
0
110
機能追加とリーダー業務の類似性
rinchoku
2
1.3k
Cache Me If You Can
ryunen344
2
3.1k
Navigation 2 を 3 に移行する(予定)ためにやったこと
yokomii
0
340
楽して成果を出すためのセルフリソース管理
clipnote
0
190
Deep Dive into Kotlin Flow
jmatsu
1
370
MCPでVibe Working。そして、結局はContext Eng(略)/ Working with Vibe on MCP And Context Eng
rkaga
5
2.3k
Design Foundational Data Engineering Observability
sucitw
3
200
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
696
190k
Fireside Chat
paigeccino
39
3.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
53k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
Rails Girls Zürich Keynote
gr2m
95
14k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Site-Speed That Sticks
csswizardry
10
820
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Mobile First: as difficult as doing things right
swwweet
224
9.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
188
55k
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