File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
docs/start/framework/react/guide Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,28 @@ A no-op (short for "no operation") is a function that does nothing when executed
8383function noop() {}
8484```
8585
86+ ### Restricting the type of the implementations
87+
88+ You can use ` .$withType<TFn>() ` to enforce the type of both the server and client implementations matches the same function signature.
89+
90+ ``` tsx
91+ import { createIsomorphicFn } from ' @tanstack/react-start'
92+ import type { Environment } from ' @/types/environment'
93+
94+ const getEnv = createIsomorphicFn ()
95+ .$withType <() => Environment >()
96+ .server (() => ' server' )
97+ .client (() => ' client' )
98+
99+ const env = getEnv ()
100+ // ^? Environment
101+ ```
102+
103+ You will get a type error if either implementation mismatches from the function signature passed to ` $withType ` .
104+
105+ > [ !NOTE]
106+ > When using ` $withType() ` , TypeScript will enforce that you define both the server and client implementations.
107+
86108---
87109
88110## ` env ` Only Functions
You can’t perform that action at this time.
0 commit comments