-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| export type TraphConfig<I,O> = { | ||
| [K in keyof O]: (i: I, o: O) => O[K] | ||
| } | ||
|
|
||
| interface TraphTransformer<I,O> { | ||
| (input: I): O | ||
| lazy: (input: I) => O | ||
| } | ||
|
|
||
| declare function traph<I = Record<string,any>,O = Record<string,any>>(config: TraphConfig<I,O>): TraphTransformer<I,O> | ||
|
|
||
| export default traph |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { expectType, expectAssignable, expectError } from "tsd" | ||
| import traph from "." | ||
|
|
||
| type Input = { in: number[] } | ||
| type Output = { out: number } | ||
|
|
||
| const stats = traph<Input, Output>({ | ||
| out: (i,o) => { | ||
| expectType<Input>(i) | ||
| expectType<Output>(o) | ||
| return i.in.length | ||
| } | ||
| }) | ||
|
|
||
| expectAssignable<(i: Input) => Output>(stats) | ||
| expectType<(i: Input) => Output>(stats.lazy) | ||
|
|
||
| declare const data: Input | ||
| expectType<Output>(stats(data)) | ||
|
|
||
| expectError(traph<Input,Output>({})) | ||
| expectError(traph<Input,Output>({out: "string value"})) | ||
| expectError(traph<Input,Output>({out: (i,o) => "string value"})) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,15 @@ | |
| "lint": "eslint index.js", | ||
| "test:watch": "ava --watch", | ||
| "test": "npm run lint && ava", | ||
| "prepublish": "npm run build && npm test" | ||
| "test:types": "tsd", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| "prepublish": "npm run build && npm test && npm run test:types" | ||
| }, | ||
| "main": "dist/index.js", | ||
| "files": [ | ||
| "dist" | ||
| "dist", | ||
| "index.d.ts" | ||
| ], | ||
| "type": "index.d.ts", | ||
| "ava": { | ||
| "require": [ | ||
| "babel-register" | ||
|
|
@@ -31,7 +34,8 @@ | |
| "eslint-config-standard": "7.0.0-beta.0", | ||
| "eslint-plugin-ava": "^4.1.0", | ||
| "eslint-plugin-promise": "^3.4.1", | ||
| "eslint-plugin-standard": "^2.0.1" | ||
| "eslint-plugin-standard": "^2.0.1", | ||
| "tsd": "^0.11.0" | ||
| }, | ||
| "dependencies": {} | ||
| } | ||
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.
🤯