expect-type
Advanced tools
Comparing version 0.7.3 to 0.7.4
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.7.4](https://github.com/mmkal/ts/compare/expect-type@0.7.3...expect-type@0.7.4) (2020-05-14) | ||
### Bug Fixes | ||
* stricter equal ([#33](https://github.com/mmkal/ts/issues/33)) ([1f9a8c7](https://github.com/mmkal/ts/commit/1f9a8c7fe7ce962e9d6e2d8ddffeee81bce1ca31)) | ||
## [0.7.3](https://github.com/mmkal/ts/compare/expect-type@0.7.2...expect-type@0.7.3) (2020-05-13) | ||
@@ -8,0 +19,0 @@ |
@@ -40,2 +40,5 @@ "use strict"; | ||
}); | ||
test('`.toEqualTypeOf` distinguishes between deeply-nested `any` and `unknown` properties', () => { | ||
__1.expectTypeOf().not.toEqualTypeOf(); | ||
}); | ||
test('Test for basic javascript types', () => { | ||
@@ -42,0 +45,0 @@ __1.expectTypeOf(() => 1).toBeFunction(); |
@@ -52,2 +52,66 @@ "use strict"; | ||
}); | ||
test('parity with IsExact from conditional-type-checks', () => { | ||
// lifted from https://github.com/dsherret/conditional-type-checks/blob/01215056e8b97a28c5b0311b42ed48c70c8723fe/tests.ts#L18-L63 | ||
/** shim conditional-type-check's `assert` */ | ||
const assert = (_result) => true; | ||
// basic test for `assert` shim: | ||
__1.expectTypeOf(assert).toBeCallableWith(true); | ||
__1.expectTypeOf(assert).toBeCallableWith(false); | ||
__1.expectTypeOf(assert).returns.toBeBoolean(); | ||
// basic test for `IsExact` shim: | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
// test for false negatives in shims: | ||
// @ts-expect-error | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
// @ts-expect-error | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
// @ts-expect-error | ||
assert(false); | ||
// @ts-expect-error | ||
assert(true); | ||
// conditional-type-check `IsExact` tests, copy-pasted directly: | ||
// matching | ||
assert(true); | ||
assert(true); | ||
assert(true); | ||
assert(true); // ok to have any for both | ||
assert(true); | ||
assert(true); | ||
assert(true); | ||
assert(true); | ||
assert(true); | ||
assert(true); | ||
assert(true); | ||
assert(true); | ||
assert(true); | ||
// not matching | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); | ||
assert(false); // these are different | ||
}); | ||
//# sourceMappingURL=types.test.js.map |
@@ -12,5 +12,8 @@ export declare type Not<T extends boolean> = T extends true ? false : true; | ||
export declare type IsNeverOrAny<T> = Or<[IsNever<T>, IsAny<T>]>; | ||
declare type DeepBrandAny<T> = IsAny<T> extends true ? Secret : { | ||
[K in keyof T]: DeepBrandAny<T[K]>; | ||
}; | ||
export declare type Extends<L, R> = L extends R ? true : false; | ||
export declare type Equal<Left, Right> = And<[Extends<Left, Right>, // prettier-break | ||
Extends<Right, Left>, Extends<keyof Left, keyof Right>, Extends<keyof Right, keyof Left>]>; | ||
export declare type StrictExtends<L, R> = Extends<DeepBrandAny<L>, DeepBrandAny<R>>; | ||
export declare type Equal<Left, Right> = And<[StrictExtends<Left, Right>, StrictExtends<Right, Left>, StrictExtends<keyof Left, keyof Right>, StrictExtends<keyof Right, keyof Left>]>; | ||
export declare type Params<Actual> = Actual extends (...args: infer P) => any ? P : never; | ||
@@ -17,0 +20,0 @@ export declare type ConstructorParams<Actual> = Actual extends new (...args: infer P) => any ? Actual extends new () => any ? P | [] : P : never; |
{ | ||
"name": "expect-type", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"repository": "https://github.com/mmkal/ts", | ||
@@ -21,3 +21,3 @@ "homepage": "https://github.com/mmkal/ts/tree/master/packages/expect-type#readme", | ||
], | ||
"gitHead": "56bed6ba6c3fa7eca06c9f73adf104438e9b0f8a" | ||
"gitHead": "1ac4c284a360ae8fe0f86dd87b64851869b1de37" | ||
} |
@@ -133,2 +133,8 @@ # expect-type | ||
`.toEqualTypeOf` distinguishes between deeply-nested `any` and `unknown` properties: | ||
```typescript | ||
expectTypeOf<{deeply: {nested: any}}>().not.toEqualTypeOf<{deeply: {nested: unknown}}>() | ||
``` | ||
Test for basic javascript types: | ||
@@ -289,2 +295,2 @@ | ||
- built into existing tooling. No extra build step, cli tool, IDE extension, or lint plugin is needed. Just import the function and start writing tests. Failures will be at compile time - they'll appear in your IDE and when you run `tsc`. | ||
- simple implementation with no dependencies. ~100 lines of code - [take a look!](https://github.com/mmkal/ts/tree/56bed6b/packages/expect-type/src/index.ts) | ||
- simple implementation with no dependencies. ~100 lines of code - [take a look!](https://github.com/mmkal/ts/tree/1ac4c28/packages/expect-type/src/index.ts) |
@@ -57,2 +57,6 @@ import {expectTypeOf} from '..' | ||
test('`.toEqualTypeOf` distinguishes between deeply-nested `any` and `unknown` properties', () => { | ||
expectTypeOf<{deeply: {nested: any}}>().not.toEqualTypeOf<{deeply: {nested: unknown}}>() | ||
}) | ||
test('Test for basic javascript types', () => { | ||
@@ -59,0 +63,0 @@ expectTypeOf(() => 1).toBeFunction() |
@@ -65,1 +65,76 @@ import * as a from '..' | ||
}) | ||
test('parity with IsExact from conditional-type-checks', () => { | ||
// lifted from https://github.com/dsherret/conditional-type-checks/blob/01215056e8b97a28c5b0311b42ed48c70c8723fe/tests.ts#L18-L63 | ||
/** shim conditional-type-check's `assert` */ | ||
const assert = <T extends boolean>(_result: T) => true | ||
/** shim conditional-type-check's `IsExact` using `Equal` */ | ||
type IsExact<T, U> = a.Equal<T, U> | ||
// basic test for `assert` shim: | ||
expectTypeOf(assert).toBeCallableWith(true) | ||
expectTypeOf(assert).toBeCallableWith(false) | ||
expectTypeOf(assert).returns.toBeBoolean() | ||
// basic test for `IsExact` shim: | ||
expectTypeOf<IsExact<0, 0>>().toEqualTypeOf<true>() | ||
expectTypeOf<IsExact<0, 1>>().toEqualTypeOf<false>() | ||
// test for false negatives in shims: | ||
// @ts-expect-error | ||
expectTypeOf<IsExact<0, 0>>().toEqualTypeOf<false>() | ||
// @ts-expect-error | ||
expectTypeOf<IsExact<0, 1>>().toEqualTypeOf<true>() | ||
// @ts-expect-error | ||
assert<IsExact<0, 0>>(false) | ||
// @ts-expect-error | ||
assert<IsExact<0, 1>>(true) | ||
// conditional-type-check `IsExact` tests, copy-pasted directly: | ||
// matching | ||
assert<IsExact<string | number, string | number>>(true) | ||
assert<IsExact<string | number | Date, string | number | Date>>(true) | ||
assert<IsExact<string | undefined, string | undefined>>(true) | ||
assert<IsExact<any, any>>(true) // ok to have any for both | ||
assert<IsExact<unknown, unknown>>(true) | ||
assert<IsExact<never, never>>(true) | ||
assert<IsExact<{}, {}>>(true) | ||
assert<IsExact<{prop: string}, {prop: string}>>(true) | ||
assert<IsExact<{prop: {prop: string}}, {prop: {prop: string}}>>(true) | ||
assert<IsExact<{prop: never}, {prop: never}>>(true) | ||
assert<IsExact<{prop: any}, {prop: any}>>(true) | ||
assert<IsExact<{prop: unknown}, {prop: unknown}>>(true) | ||
assert<IsExact<Window, Window>>(true) | ||
// not matching | ||
assert<IsExact<string | number | Date, string | number>>(false) | ||
assert<IsExact<string, string | number>>(false) | ||
assert<IsExact<string | undefined, string>>(false) | ||
assert<IsExact<string | undefined, any | string>>(false) | ||
assert<IsExact<any | string | undefined, string>>(false) | ||
assert<IsExact<string, any>>(false) | ||
assert<IsExact<string, unknown>>(false) | ||
assert<IsExact<string, never>>(false) | ||
assert<IsExact<never, never | string>>(false) | ||
assert<IsExact<unknown, any>>(false) | ||
assert<IsExact<never, any>>(false) | ||
assert<IsExact<MouseEvent | Window, MouseEvent>>(false) | ||
assert<IsExact<{name: string; other?: Date}, {name: string}>>(false) | ||
assert<IsExact<{prop: Date}, {prop: string}>>(false) | ||
assert<IsExact<{other?: Date}, {prop?: string}>>(false) | ||
assert<IsExact<{prop: {prop?: string}}, {prop: {prop: string}}>>(false) | ||
assert<IsExact<{prop: any}, {prop: string}>>(false) | ||
assert<IsExact<{prop: any}, {prop: unknown}>>(false) | ||
assert<IsExact<{prop: any}, {prop: never}>>(false) | ||
assert<IsExact<{prop: unknown}, {prop: never}>>(false) | ||
assert<IsExact<{prop: {prop: unknown}}, {prop: {prop: any}}>>(false) | ||
assert<IsExact<{prop: {prop: unknown}}, {prop: {prop: never}}>>(false) | ||
assert<IsExact<{prop: {prop: any}}, {prop: {prop: never}}>>(false) | ||
assert<IsExact<{prop: string}, {prop: never}>>(false) | ||
assert<IsExact<{prop: {prop: any}}, {prop: {prop: string}}>>(false) | ||
assert<IsExact<{prop: any} | {prop: string}, {prop: number} | {prop: string}>>(false) | ||
assert<IsExact<{prop: string | undefined}, {prop?: string}>>(false) // these are different | ||
}) |
@@ -16,9 +16,15 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
type DeepBrandAny<T> = IsAny<T> extends true // avoid `any` matching `unknown` | ||
? Secret | ||
: {[K in keyof T]: DeepBrandAny<T[K]>} | ||
export type Extends<L, R> = L extends R ? true : false | ||
export type StrictExtends<L, R> = Extends<DeepBrandAny<L>, DeepBrandAny<R>> | ||
export type Equal<Left, Right> = And< | ||
[ | ||
Extends<Left, Right>, // prettier-break | ||
Extends<Right, Left>, | ||
Extends<keyof Left, keyof Right>, | ||
Extends<keyof Right, keyof Left> | ||
StrictExtends<Left, Right>, | ||
StrictExtends<Right, Left>, | ||
StrictExtends<keyof Left, keyof Right>, | ||
StrictExtends<keyof Right, keyof Left> | ||
] | ||
@@ -25,0 +31,0 @@ > |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
235657
3622
295