expect-type
Advanced tools
Comparing version 0.7.8 to 0.7.9
@@ -6,2 +6,14 @@ # Change Log | ||
## [0.7.9](https://github.com/mmkal/ts/compare/expect-type@0.7.8...expect-type@0.7.9) (2020-07-28) | ||
### Bug Fixes | ||
* **toEqualTypeOf:** stop functions incorrectly matching ([#99](https://github.com/mmkal/ts/issues/99)) ([61a1bc3](https://github.com/mmkal/ts/commit/61a1bc37bc43ae2b737b588f3a40e584cf40e730)) | ||
## [0.7.8](https://github.com/mmkal/ts/compare/expect-type@0.7.7...expect-type@0.7.8) (2020-07-09) | ||
@@ -8,0 +20,0 @@ |
@@ -12,7 +12,11 @@ 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]>; | ||
declare type DeepBrand<T> = IsAny<T> extends true ? Secret : T extends (...args: infer P) => infer R ? { | ||
params: DeepBrand<P>; | ||
return: DeepBrand<R>; | ||
function: Secret; | ||
} : { | ||
[K in keyof T]: DeepBrand<T[K]>; | ||
}; | ||
export declare type Extends<L, R> = L extends R ? true : false; | ||
export declare type StrictExtends<L, R> = Extends<DeepBrandAny<L>, DeepBrandAny<R>>; | ||
export declare type StrictExtends<L, R> = Extends<DeepBrand<L>, DeepBrand<R>>; | ||
export declare type Equal<Left, Right> = And<[StrictExtends<Left, Right>, StrictExtends<Right, Left>, StrictExtends<keyof Left, keyof Right>, StrictExtends<keyof Right, keyof Left>]>; | ||
@@ -19,0 +23,0 @@ export declare type Params<Actual> = Actual extends (...args: infer P) => any ? P : never; |
{ | ||
"name": "expect-type", | ||
"version": "0.7.8", | ||
"version": "0.7.9", | ||
"repository": { | ||
@@ -25,3 +25,3 @@ "type": "git", | ||
], | ||
"gitHead": "fe93eb5b181daa06beccb74692b32e19180a33c9" | ||
"gitHead": "9c44d44ae9785c7c466d765269b5851dd02646c3" | ||
} |
@@ -194,5 +194,27 @@ # expect-type | ||
Assert on function parameters (using `.parameter(n)` or `.parameters`) and return values (using `.returns`): | ||
`.toEqualTypeOf` can be used to distinguish between functions: | ||
```typescript | ||
type NoParam = () => void | ||
type HasParam = (s: string) => void | ||
expectTypeOf<NoParam>().not.toEqualTypeOf<HasParam>() | ||
``` | ||
But often it's preferable to use `.parameters` or `.returns` for more specific function assertions: | ||
```typescript | ||
type NoParam = () => void | ||
type HasParam = (s: string) => void | ||
expectTypeOf<NoParam>().parameters.toEqualTypeOf<[]>() | ||
expectTypeOf<NoParam>().returns.toEqualTypeOf<void>() | ||
expectTypeOf<HasParam>().parameters.toEqualTypeOf<[string]>() | ||
expectTypeOf<HasParam>().returns.toEqualTypeOf<void>() | ||
``` | ||
More examples of ways to work with functions - parameters using `.parameter(n)` or `.parameters`, and return values using `.returns`: | ||
```typescript | ||
const f = (a: number) => [a, a] | ||
@@ -295,2 +317,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/fe93eb5/packages/expect-type/src/index.ts) | ||
- simple implementation with no dependencies. ~100 lines of code - [take a look!](https://github.com/mmkal/ts/tree/9c44d44/packages/expect-type/src/index.ts) |
@@ -16,8 +16,10 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
type DeepBrandAny<T> = IsAny<T> extends true // avoid `any` matching `unknown` | ||
type DeepBrand<T> = IsAny<T> extends true // avoid `any` matching `unknown` | ||
? Secret | ||
: {[K in keyof T]: DeepBrandAny<T[K]>} | ||
: T extends (...args: infer P) => infer R // avoid functions with different params/return values matching | ||
? {params: DeepBrand<P>; return: DeepBrand<R>; function: Secret} | ||
: {[K in keyof T]: DeepBrand<T[K]>} | ||
export type Extends<L, R> = L extends R ? true : false | ||
export type StrictExtends<L, R> = Extends<DeepBrandAny<L>, DeepBrandAny<R>> | ||
export type StrictExtends<L, R> = Extends<DeepBrand<L>, DeepBrand<R>> | ||
@@ -24,0 +26,0 @@ export type Equal<Left, Right> = And< |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
49517
272
317
1