Skip to content

Commit 03daae9

Browse files
committed
add keyofStringsOnly
1 parent c4546d9 commit 03daae9

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

packages/browser/src/core/user/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const defaults = {
3737

3838
export type StoreType = 'cookie' | 'localStorage' | 'memory'
3939

40-
type StringKeys<T> = Exclude<keyof T, number | symbol>
4140
type StorageObject = Record<string, unknown>
4241

4342
class Store {
@@ -217,11 +216,11 @@ export class UniversalStorage<Data extends StorageObject = StorageObject> {
217216
}
218217

219218
/*
220-
This is to support few scenarios where:
221-
- value exist in one of the stores ( as a result of other stores being cleared from browser ) and we want to resync them
219+
This is to support few scenarios where:
220+
- value exist in one of the stores ( as a result of other stores being cleared from browser ) and we want to resync them
222221
- read values in AJS 1.0 format ( for customers after 1.0 --> 2.0 migration ) and then re-write them in AJS 2.0 format
223222
*/
224-
public getAndSync<K extends StringKeys<Data>>(
223+
public getAndSync<K extends keyof Data>(
225224
key: K,
226225
storeTypes?: StoreType[]
227226
): Data[K] | null {
@@ -235,7 +234,7 @@ export class UniversalStorage<Data extends StorageObject = StorageObject> {
235234
) as Data[K] | null
236235
}
237236

238-
public get<K extends StringKeys<Data>>(
237+
public get<K extends keyof Data>(
239238
key: K,
240239
storeTypes?: StoreType[]
241240
): Data[K] | null {
@@ -250,7 +249,7 @@ export class UniversalStorage<Data extends StorageObject = StorageObject> {
250249
return null
251250
}
252251

253-
public set<K extends StringKeys<Data>>(
252+
public set<K extends keyof Data>(
254253
key: K,
255254
value: Data[K] | null,
256255
storeTypes?: StoreType[]
@@ -261,10 +260,7 @@ export class UniversalStorage<Data extends StorageObject = StorageObject> {
261260
return value
262261
}
263262

264-
public clear<K extends StringKeys<Data>>(
265-
key: K,
266-
storeTypes?: StoreType[]
267-
): void {
263+
public clear<K extends keyof Data>(key: K, storeTypes?: StoreType[]): void {
268264
for (const store of this.getStores(storeTypes)) {
269265
store.remove(key)
270266
}

packages/browser/src/plugins/validation/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ export function isFunction(obj: unknown): obj is Function {
1414
return typeof obj === 'function'
1515
}
1616

17-
export function isPlainObject(
18-
obj: unknown
19-
): obj is Record<string | symbol | number, any> {
17+
export function isPlainObject(obj: unknown): obj is Record<string, any> {
2018
return (
2119
Object.prototype.toString.call(obj).slice(8, -1).toLowerCase() === 'object'
2220
)

packages/core/src/validation/helpers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ export function isFunction(obj: unknown): obj is Function {
1212
return typeof obj === 'function'
1313
}
1414

15-
export function isPlainObject(
16-
obj: unknown
17-
): obj is Record<string | symbol | number, any> {
15+
export function isPlainObject(obj: unknown): obj is Record<string, any> {
1816
return (
1917
Object.prototype.toString.call(obj).slice(8, -1).toLowerCase() === 'object'
2018
)

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"esModuleInterop": true,
55
"skipLibCheck": true,
66
"noUnusedLocals": true,
7+
"keyofStringsOnly": true,
78
"noUnusedParameters": true
89
},
910
"ts-node": {

0 commit comments

Comments
 (0)