Skip to content

Commit 92b993b

Browse files
authoredMay 29, 2024
ai/rsc: Improve getAIState and getMutableAIState types (#1458)
1 parent 7a4ba3d commit 92b993b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed
 

‎.changeset/flat-bugs-grin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ai': patch
3+
---
4+
5+
ai/rsc: improve getAIState and getMutableAIState types

‎packages/core/rsc/ai-state.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ export function sealMutableAIState() {
6464
* @example const state = getAIState() // Get the entire AI state
6565
* @example const field = getAIState('key') // Get the value of the key
6666
*/
67-
function getAIState<AI extends AIProvider = any>(): InferAIState<AI, any>;
67+
function getAIState<AI extends AIProvider = any>(): Readonly<
68+
InferAIState<AI, any>
69+
>;
6870
function getAIState<AI extends AIProvider = any>(
6971
key: keyof InferAIState<AI, any>,
70-
): InferAIState<AI, any>[typeof key];
72+
): Readonly<InferAIState<AI, any>[typeof key]>;
7173
function getAIState<AI extends AIProvider = any>(
7274
...args: [] | [key: keyof InferAIState<AI, any>]
7375
) {
@@ -183,10 +185,10 @@ function getMutableAIState<AI extends AIProvider = any>(
183185
)}" field from the AI state because it's not an object.`,
184186
);
185187
}
186-
return store.currentState[key];
188+
return store.currentState[key] as Readonly<AIStateWithKey>;
187189
}
188190

189-
return store.currentState as AIState;
191+
return store.currentState as Readonly<AIState>;
190192
},
191193
update: function update(newAIState: NewStateOrUpdater) {
192194
doUpdate(newAIState, false);

0 commit comments

Comments
 (0)