Skip to content

Commit

Permalink
loosen types (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
dferber90 committed Oct 23, 2022
1 parent 90cd901 commit 311fedd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-bobcats-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/edge-config': patch
---

loosen edge config item value type to be "any"
32 changes: 13 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { EdgeConfigItemValue, EmbeddedEdgeConfig } from './types';

export type { EdgeConfigItemValue } from './types';
import type { EmbeddedEdgeConfig } from './types';

declare global {
/* eslint-disable camelcase */
Expand Down Expand Up @@ -116,10 +114,10 @@ function getLocalEdgeConfig(edgeConfigId: string): EmbeddedEdgeConfig | null {
* Edge Config Client
*/
export interface EdgeConfigClient {
get: <T extends EdgeConfigItemValue>(key: string) => Promise<T | undefined>;
getAll: <T extends Record<string, EdgeConfigItemValue>>(
keys?: (keyof T)[],
) => Promise<T | undefined>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get: <T = any>(key: string) => Promise<T | undefined>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getAll: <T = any>(keys?: (keyof T)[]) => Promise<T | undefined>;
has: (key: string) => Promise<boolean>;
digest: () => Promise<string>;
}
Expand Down Expand Up @@ -157,9 +155,8 @@ export function createEdgeConfigClient(
// return api which uses the local edge config if one exists
if (localEdgeConfig) {
return {
get<T extends EdgeConfigItemValue>(
key: string,
): Promise<T | undefined> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async get<T = any>(key: string): Promise<T | undefined> {
assertIsDefined(localEdgeConfig); // always defined, but make ts happy
assertIsKey(key);

Expand All @@ -169,9 +166,8 @@ export function createEdgeConfigClient(
// This makes it consistent with the real API.
return Promise.resolve(clone(localEdgeConfig.items[key]) as T);
},
async getAll<T extends Record<string, EdgeConfigItemValue>>(
keys?: (keyof T)[],
): Promise<T | undefined> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async getAll<T = any>(keys?: (keyof T)[]): Promise<T | undefined> {
assertIsDefined(localEdgeConfig);
assertIsKeys(keys);

Expand All @@ -193,9 +189,8 @@ export function createEdgeConfigClient(
}

return {
async get<T extends EdgeConfigItemValue>(
key: string,
): Promise<T | undefined> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async get<T = any>(key: string): Promise<T | undefined> {
assertIsKey(key);
return fetch(`${url}/item/${key}`, { headers }).then<
T | undefined,
Expand Down Expand Up @@ -241,9 +236,8 @@ export function createEdgeConfigClient(
},
);
},
async getAll<T extends Record<string, EdgeConfigItemValue>>(
keys?: (keyof T)[],
): Promise<T | undefined> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async getAll<T = any>(keys?: (keyof T)[]): Promise<T | undefined> {
if (Array.isArray(keys)) assertIsKeys(keys);

const search = Array.isArray(keys)
Expand Down
11 changes: 2 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
export type EdgeConfigItemValue =
| string
| number
| boolean
| null
| { [key: string | number]: EdgeConfigItemValue }
| EdgeConfigItemValue[];

export interface EmbeddedEdgeConfig {
digest: string;
items: Record<string, EdgeConfigItemValue>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
items: Record<string, any>;
}

0 comments on commit 311fedd

Please sign in to comment.