-
Notifications
You must be signed in to change notification settings - Fork 28
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
fix: promises where not allowed by type #61
Conversation
@@ -13,7 +13,7 @@ | |||
"tdd": "mocha --watch", | |||
"test": "npm run lint && npm run test:once && npm run test:types", | |||
"test:once": "nyc --reporter=lcovonly --reporter=html mocha", | |||
"test:types": "dtslint --expectOnly --localTs node_modules/typescript/lib types", |
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.
this didn't work before I made changes, kept returning
> dtslint --expectOnly --localTs node_modules/typescript/lib types
Error: Errors in typescript@local for external dependencies:
../src/Schema.ts(33,37): error TS2345: Argument of type 'DataType' is not assignable to parameter of type 'PlainObject<any>'.
../src/Schema.ts(48,37): error TS2345: Argument of type 'DataType' is not assignable to parameter of type 'PlainObject<any>'.
at /Users/jspears/dev/schema-typed/node_modules/dtslint/bin/index.js:207:19
at Generator.next (<anonymous>)
at fulfilled (/Users/jspears/dev/schema-typed/node_modules/dtslint/bin/index.js:6:58)
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.
dtslint
is a linting tool used by the current library before refactoring through typescript, I think it can be removed, because there is eslint as a type checking tool.
function isObj(o: unknown): o is Record<PropertyKey, unknown> { | ||
return o != null && (typeof o === 'object' || typeof o == 'function'); | ||
} | ||
function isPromiseLike(v: unknown): v is Promise<unknown> { |
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.
sometimes people don't use real promises. Its sad, but true.
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.
👌
src/utils/createValidator.ts
Outdated
@@ -19,6 +24,8 @@ export function createValidator<V, D, E>(data?: D, name?: string | string[]) { | |||
name: Array.isArray(name) ? name.join('.') : name | |||
}) | |||
}; | |||
} else if (isPromiseLike(checkResult)) { | |||
throw new Error('synchronous validator had an async result'); |
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.
This seems like the safest thing to do. I would hate for somebody to make an async call that never resolves.
@@ -19,6 +24,8 @@ export function createValidator<V, D, E>(data?: D, name?: string | string[]) { | |||
name: Array.isArray(name) ? name.join('.') : name | |||
}) | |||
}; | |||
} else if (isPromiseLike(checkResult)) { |
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.
It would be nice to be able to add test cases for the changes here.
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.
Good point added a test.
Fixed in 2.0.4 |
This adds typescript types allowing for promise based validators.
#60