This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 267
Typings
Meirion Hughes edited this page Sep 15, 2017
·
5 revisions
By default, typescript should be able to infer the option-types based off the AbstractLevelDOWN
(typed) implementation you give it. For example, give:
import * as levelup from 'levelup';
import * as leveldown from 'leveldown';
import * as encoding from 'encoding-down';
let db = levelup(encode(leveldown<string, number>('./db')));
then the db
type will be automatically inferred, and equivalent to:
type DbType = levelup.LevelUp<
string,
number,
leveldown.LevelDownOptions,
leveldown.LevelDownPutOptions & encoding.CodecOptions,
leveldown.LevelDownGetOptions & encoding.CodecOptions,
leveldown.LevelDownDeleteOptions & encoding.CodecOptions,
leveldown.LevelDownIteratorOptions<string, number> & encoding.CodecOptions,
leveldown.LevelDownBatchOptions & encoding.CodecOptions>
Due to limitations on typescript, it is not possible to retype the TKey
and TValue
between encoding-leveldown
and leveldown
. As such, it is recommended you type your base-database (i.e. leveldown<string, number>('./db')
) with the key/value types you wish to end-up using with levelup