-
Notifications
You must be signed in to change notification settings - Fork 5
Add type definitions #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Wow thanks!!! Is it impossible to infer output types though? |
| @@ -0,0 +1,23 @@ | |||
| import { expectType, expectAssignable, expectError } from "tsd" | |||
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.
Oh my god, I missed this library completely... I'm losing my edge
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.
🤯
| "test:watch": "ava --watch", | ||
| "test": "npm run lint && ava", | ||
| "prepublish": "npm run build && npm test" | ||
| "test:types": "tsd", |
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.
How could we call both ava and tsd with the yarn test and yarn test:watch scripts?
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.
Not sure if I get what you mean. Are you wondering how to call both ava and tsd in watch mode at the same time with one call? However, a "watch" option seems to be missing in tsd
|
I'm afraid so. I think that circular reference is unavoidable. I've tried to infer Output type from With these types, the output is inferred when getters use only const transform = traph({
fullName: i => `${i.first} ${i.last}`,
initials: i => `${i.first[0].toUpperCase()}.${i.last[0].toUpperCase()}.`,
})
const output = transform({ first: 'Richard', last: 'Feynman' })
|
This adds type definitions to
traphfunction.It is possible to have type checking for the object passed to
traphfunction by passing two types: the expected input object type and the expected output object type.In each callback
itype isInandotype isOut.Also, the argument passed to
traphmust have all and only the keys ofOut, where every key must have proper return type:This PR adds
tsdtest too.