We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Tagged types for Expectations
Type safety
export class ExpectError extends Error { public constructor(message: string) { super(message) this.name = 'ExpectError' } } interface AnyMatchers { [key: string]: (expectation: any, ...args: any[]) => boolean } type OmitFirstArg<A> = A extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never type Expectations<M extends AnyMatchers> = { [K in keyof M]: OmitFirstArg<M[K]> } type NegatedExpectations<M extends AnyMatchers> = Expectations<M> & { not: Expectations<M> } type ExpectResult<A, E> = { matcher: string error?: ExpectError status: ExpectStatus actual: A expected: E } enum ExpectStatus { PASS = 'Pass', FAIL = 'Fail', } const _expectFail = <F, P = never> (fail: F): ExpectationResult<F, P> => ({ _status: ExpectStatus.FAIL, fail }) const _expectPass = <P, F = never> (pass: P): ExpectationResult<F, P> => ({ _status: ExpectStatus.PASS, pass }) const expectPass: <F = never, P = never> (pass: P) => ExpectationResult<F, P> = _expectPass const expectFail: <F = never, P = never> (fail: F) => ExpectationResult<F, P> = _expectFail interface IExpectFail<F> { readonly _status: ExpectStatus.FAIL readonly fail: F } interface IExpectPass<P> { readonly _status: ExpectStatus.PASS readonly pass: P } type ExpectationResult<F, P> = IExpectFail<F> | IExpectPass<P>
The text was updated successfully, but these errors were encountered:
@sh7dm let me know if you have any opinions when you have time.
Sorry, something went wrong.
Well, type-safe design should look perfectly here. Key Onyx feature is being based on TypeScript.
ElijahKotyluk
No branches or pull requests
Proposed Feature
Tagged types for Expectations
Motivation
Type safety
Example
The text was updated successfully, but these errors were encountered: