Skip to content

Commit 2f4e0e3

Browse files
committed
Add typed createIdentify
1 parent 26d78c9 commit 2f4e0e3

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/identify.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { FsUserContext } from '@flagsync/node-sdk';
2+
import { Identify } from '@vercel/flags';
3+
4+
type ExtractParams<T> = T extends (params: infer P) => any ? P : never;
5+
6+
export const createIdentify =
7+
(
8+
callback: (
9+
params: ExtractParams<Identify<FsUserContext>>,
10+
) => Promise<FsUserContext> | FsUserContext,
11+
): Identify<FsUserContext> =>
12+
(params) =>
13+
callback(params);

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ export {
1919
createJsonFlagAdaptor,
2020
createNumberFlagAdaptor,
2121
} from './adapter';
22+
23+
export { createIdentify } from './identify';

src/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export type JsonPrimitive = string | number | boolean | null;
2-
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
3-
export interface JsonArray extends Array<JsonValue> {}
4-
export interface JsonObject {
5-
[key: string]: JsonValue;
6-
}
1+
export type JsonPrimitive = string | number | boolean | null;
2+
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
3+
export type JsonArray = Array<JsonValue>;
4+
export interface JsonObject {
5+
[key: string]: JsonValue;
6+
}

0 commit comments

Comments
 (0)