-
-
Notifications
You must be signed in to change notification settings - Fork 264
feat: add typescript definitions #475
Conversation
|
the plugin augmentation: function down(): levelup.AbstractDown<{ fast: boolean }, any, any, any, { foo: boolean }> {
return undefined;
}
function plugin<P, G, D, B, O>(
store: levelup.AbstractDown<P, G, D, B, O>
): levelup.AbstractDown<P & {slow: boolean}, any, any, any, { foo: boolean }> {
return undefined;
}
let db = levelup(plugin(down()));
db.put("hello", "world", { fast: true }, ()=>{});
|
|
I don't feel that I'm qualified to review this. Maybe someone can fill in here? |
|
main issue is while the typescript compiler is able to correctly infer and check the types after they've been augmented by any plugins you use, vscode intellisense is not as able keep up and gives up trying to work out the options type. basically, with this approach you'd currently not get intellisense on the levelup ctor options. There is an alternative way to do the typings (so they are extendable) but it requires using a global definition - so it would be the same for every instance of levelup. |
b584a68 to
08d6e1f
Compare
|
I'm not qualified to review this either. Instead, would it be possible to add a test suite for this? |
|
@juliangruber I could add a test to ensure the typescript compiler is happy / unhappy with common use-cases. |
|
Would it be possible to run the whole test suite through typescript actually? |
Mind blown |
|
hmm not sure; I've not used the test runner you use. If you'd gone with mocha, it would have been a minor cli argument to switch to typescript. :) |
|
The tests (individually) can be run with And to run the whole suite, something like: |
Brilliant idea if we can get that to work |
|
It very nearly works; unfortunately typescript doesn't understand
I can trick typescript with: LevelUP.prototype.emit = EventEmitter.prototype.emit
LevelUP.prototype.once = EventEmitter.prototype.once
inherits(LevelUP, EventEmitter); |
|
@MeirionHughes Maybe it's possible to provide that information via typescript definitions? Maybe not ideal but as a workaround. |
|
I've found a workaround (see edit above). Its working. I'm just fixing typing errors now. |
110c1ea to
8779907
Compare
.travis.yml
Outdated
| - export JOBS=max | ||
|
|
||
| before_script: | ||
| - npm install typescript ts-node -g |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to add these as devDependencies instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. :)
|
Nevermind, I pulled that in. Should be enough to rebase this PR onto latest master. |
|
How about releasing |
95b4a68 to
826e9fb
Compare
|
Something is up with the tests. I can reproduce locally. |
|
yeah; error typing is wrong was missing the 2nd parameter for cause; patched Level/errors#9 Test also fails (only on travis) right at the end saying things are out of order. |
|
@ralphtheninja I'm not sure about the order errors. If you run |
It fails for me. Are you sure you don't have a globally installed |
|
Actually, I think it would be easier if you just added a script for simply running |
|
Or maybe that will cause problems on windows (e.g. a for loop in the shell running |
|
@MeirionHughes I'm experimenting locally a bit, I can make a PR on top of this PR if you like. |
bit of a fiddly one this. basically it is typed to that you can argument the
abstract-leveldownstore type and then infer:example typescript.
errorsand double-check against docs