-
-
Notifications
You must be signed in to change notification settings - Fork 52
Conversation
(We need more @Level/typescript people) |
self._nexting = false | ||
callback() | ||
callback.apply(null, arguments) |
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.
Nice one. Much more cleaner now.
I'm thinking we should mark the typings as |
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.
I'd like to suggest we add a test.ts to test TypeScript more natively.
@zixia what are the benefits? And does it involve rewriting the test suite in TypeScript? |
@vweevers The benefits would be able to do static type checking? I do not know whether ts-node do type checking when we run a After ts-node v4, we have to do a
I think we can just add one unit test file written by TypeScript, and we use |
It does (though to a lesser extent, I'm assuming), which is why we need most commits here (b1d006e for example).
Ah! I was wondering why v4 didn't work. Great, I'll upgrade |
Remaining tasks:
|
@zixia is there a way to test the types themselves? For example, this should be a failing test: const db = new AbstractLevelDOWN<string, number>('foobar')
db.put('key', 'value', (err) => {
t.ifError(err)
t.end()
}) While this one should pass: const db = new AbstractLevelDOWN<string, number>('foobar')
db.put('key', 2, (err) => {
t.ifError(err)
t.end()
}) Without tests like this, I don't know how to make |
Or in other words: how can we test that the type definitions are correct? |
const buf = Buffer.from('foo') | ||
|
||
// Key and value generics | ||
new AbstractLevelDOWN<string, string>('loc').put('key', 'value', (err: Error) => {}) |
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.
Note this isn't that valuable, as it's only positive tests, no negative tests.
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.
Also I initially created this file as test.ts
but this tripped up TypeScript's module resolution (because we also have test.js
). So I renamed it to test-types.ts
.
PTAL |
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.
Very good start to have native typescript tests!
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.
looks fine
one thing I just couldn't get right was the i.e. when
is wrong. Some other solutions I tried, but didn't really work when it came to inference at the levelup stage: manually override when needed:
overloading:
I bring it up because that case wasn't tested in this PR. This is one reason why I put the idea that the generics be removed in |
@MeirionHughes Considering the dynamic nature of everything put together ( It would simplify integration, decrease coupling, make it easier to maintain for the non-TS-savvy, and we could also increase correctness of the rest of the typings (for example, the That said, if you can find a way to make generics work, then great, go for it ;) Perhaps continue the discussion in a new ticket with @Level/typescript. As for this PR, I'm gonna squash a few commits and then we're good to merge. I'm not really happy with having to use |
* remove approximateSize() and isLevelDOWN() * make Batch value optional * add missing db property to AbstractIterator
Otherwise TypeScript doesn't see that Test inherits AbstractLevelDOWN, if defined like this: ``` function Test (location) { AbstractLevelDOWN.call(this, location) } util.inherits(Test, AbstractLevelDOWN) ``` And will complain about AbstractLevelDOWN methods being undefined on Test.
@ralphtheninja I'll update the changelog in a separate PR. |
Closes #190, #192, #193 (with a few leftover tasks I'll open issues for).