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
KoogではじめるAIエージェント開発
hiroaki404
1
220
マイベストのシンプルなデータ基盤の話 - Googleスイートとのつき合い方 / mybest-simple-data-architecture-google-nized
snhryt
0
110
Register is more than clipboard
satorunooshie
1
180
CSC305 Lecture 11
javiergs
PRO
0
320
Swift Concurrency 年表クイズ
omochi
3
210
はじめてのDSPy - 言語モデルを『プロンプト』ではなく『プログラミング』するための仕組み
masahiro_nishimi
4
17k
Introduce Hono CLI
yusukebe
6
3.3k
オープンソースソフトウェアへの解像度🔬
utam0k
18
3.2k
Inside of Swift Export
giginet
PRO
1
250
開発組織の戦略的な役割と 設計スキル向上の効果
masuda220
PRO
10
2k
釣り地図SNSにおける有料機能の実装
nokonoko1203
0
200
Pythonに漸進的に型をつける
nealle
1
140
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
We Have a Design System, Now What?
morganepeng
53
7.9k
Designing for humans not robots
tammielis
254
26k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
Six Lessons from altMBA
skipperchong
29
4k
RailsConf 2023
tenderlove
30
1.3k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
Why You Should Never Use an ORM
jnunemaker
PRO
60
9.6k
Docker and Python
trallard
46
3.6k
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