jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.22k stars 348 forks source link

TypeScript 4.3.1-rc error on resolved store name #222

Closed brunnerh closed 3 years ago

brunnerh commented 3 years ago

Not sure if this is worth looking into as TS 4.3 has not been released yet, but using this version causes store name parameters to not be resolved correctly.

E.g.

import { openDB, DBSchema } from 'idb';

async function doDatabaseStuff()
{
    const db = await openDB<DB>('documents', 1, {
        upgrade(db, oldVersion, newVersion, transaction)
        {
            // Argument of type 'string' is not assignable to parameter of type 'never'. ts(2345)
            db.createObjectStore('documents', { keyPath: 'id' });
        }
    });
}

interface DB extends DBSchema
{
    documents: {
        value: {
            id: string,
            text: string,
        }
        key: string,
    },
};

package.json:

{
    "dependencies": {
        "idb": "6.0.0",
        "typescript": "4.3.1-rc"
    }
}

[Issue Repository]

jakearchibald commented 3 years ago

Cheers. I can recreate this issue.

jakearchibald commented 3 years ago

Fixed in e3c76a59f6ab461b03ceabebc24dea826a074a76, and published as 6.1.0. Thanks for catching this!

I think this might be a TypeScript bug (and I'll file an issue with them), but I'm happy with the change here.

jakearchibald commented 3 years ago

Filed https://github.com/microsoft/TypeScript/issues/44143