Skip to content

Commit

Permalink
add TypeScript smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Feb 8, 2018
1 parent b1ed564 commit 5eb28af
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -48,7 +48,9 @@
},
"scripts": {
"test": "standard && node test.js && npm run test-ts",
"test-ts": "ts-node --type-check --no-cache test.js"
"test-ts": "npm run test-ts-types && npm run test-ts-suite",
"test-ts-types": "ts-node --type-check --no-cache test-types.ts",
"test-ts-suite": "ts-node --type-check --no-cache test.js"
},
"license": "MIT",
"engines": {
Expand Down
21 changes: 21 additions & 0 deletions test-types.ts
@@ -0,0 +1,21 @@
import { AbstractLevelDOWN } from '.'

const buf = Buffer.from('foo')

// Key and value generics
new AbstractLevelDOWN<string, string>('loc').put('key', 'value', (err: Error) => {})
new AbstractLevelDOWN<Buffer, Buffer>('loc').put(buf, buf, (err: Error) => {})
new AbstractLevelDOWN<number, object>('loc').put(1, {}, (err: Error) => {})

new AbstractLevelDOWN<string, string>('loc').get('key', (err: Error, value: string) => {})
new AbstractLevelDOWN<Buffer, Buffer>('loc').get(buf, (err: Error, value: Buffer) => {})
new AbstractLevelDOWN<number, object>('loc').get(1, (err: Error, value: object) => {})

// The generics default to "any"
new AbstractLevelDOWN('loc').put(1, {}, (err: Error) => {})
new AbstractLevelDOWN('loc').put('key', 'value', (err: Error) => {})
new AbstractLevelDOWN('loc').put(buf, false, (err: Error) => {})

new AbstractLevelDOWN('loc').get(1, (err: Error, value: any) => {})
new AbstractLevelDOWN('loc').get('key', (err: Error, value: any) => {})
new AbstractLevelDOWN('loc').get(buf, (err: Error, value: any) => {})

0 comments on commit 5eb28af

Please sign in to comment.