Skip to content

Storage export uses as unknown as double assertion #10

@oritwoen

Description

@oritwoen

In `src/storage.ts:9-11`:

export const storage = createStorage({
  driver: memoryDriver()
}) as unknown as Storage & { options?: { prefix?: string } }

This casts the unstorage instance to the Web API `Storage` interface (which has `getItem(key): string | null`, `setItem(key, value): void`, etc.) rather than the unstorage `Storage` type (which has `getItem(key): Promise`, `setItem(key, value): Promise`, etc.).

It works at runtime because the code `await`s every call, but TypeScript thinks the return types are synchronous. Any future refactor that trusts the types could silently drop awaits and break.

The `initStorage` function also uses `Object.assign(storage, createStorage({...}))` to mutate the exported object in place, which is fragile — it copies own properties but doesn't update the prototype chain, so any method that lives on the prototype won't be replaced.

Typing it as `ReturnType` (or the unstorage `Storage` type) with an extended interface for `options` would fix the type mismatch without the double assertion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions