Comment

Comment by hither_shores

> Imagine I want to test a function that operates on quite large application state but not all app state is necessary for that function

If not all app state is necessary for that function, it shouldn't require the whole app state in its arguments.

     type AppState = { databaseConnection: DatabaseConnection, env : "dev" | "prod", apiToken: string, userId: string, ... } & SomeOtherStuff

     const dropTables = (app: Pick<AppState, "databaseConnection"> & {env: "dev"} ) => app.databaseConnection.dropTables()
Conversely, if a function you don't control says it needs the whole app state, believe it.

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton