Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

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:

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 posible to retype the Key and Value between encoding-leveldown and 'leveldown'. It is recommended to type your base database (i.e. leveldown<string, number>('./db')) with the key/value types you wish to end up using with levelup

Clone this wiki locally