Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

expect-type

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expect-type - npm Package Compare versions

Comparing version 0.5.5 to 0.6.0

dist/__tests__/types.test.d.ts

17

CHANGELOG.md

@@ -6,2 +6,19 @@ # Change Log

# [0.6.0](https://github.com/mmkal/ts/compare/expect-type@0.5.5...expect-type@0.6.0) (2020-05-04)
### Bug Fixes
* keywords ([15fb566](https://github.com/mmkal/ts/commit/15fb566468a9f258c6126d24931d59bafa7cfb6f))
### Features
* toBeConstructibleWith, constructorParameters ([5a9d7fd](https://github.com/mmkal/ts/commit/5a9d7fd2c45f9eee7bffc6e6ed75e51712397b35))
## [0.5.5](https://github.com/mmkal/ts/compare/expect-type@0.5.4...expect-type@0.5.5) (2020-04-26)

@@ -8,0 +25,0 @@

9

dist/__tests__/index.test.js

@@ -70,2 +70,9 @@ "use strict";

});
test('Assert on constructor parameters', () => {
__1.expectTypeOf(Date).toBeConstructibleWith('1970');
__1.expectTypeOf(Date).toBeConstructibleWith(0);
__1.expectTypeOf(Date).toBeConstructibleWith(new Date());
__1.expectTypeOf(Date).toBeConstructibleWith();
__1.expectTypeOf(Date).constructorParameters.toEqualTypeOf();
});
test('Promise resolution types can be checked with `.resolves`', () => {

@@ -81,3 +88,3 @@ const asyncFunc = async () => 123;

const thrower = () => {
throw Error();
throw Error('oh no');
};

@@ -84,0 +91,0 @@ __1.expectTypeOf(thrower).returns.toBeNever();

9

dist/index.d.ts

@@ -15,3 +15,4 @@ export declare type Not<T extends boolean> = T extends true ? false : true;

Extends<Right, Left>, Extends<keyof Left, keyof Right>, Extends<keyof Right, keyof Left>]>;
export declare type Params<Actual> = Actual extends (...args: infer P) => any ? P : [never];
export declare type Params<Actual> = Actual extends (...args: infer P) => any ? P : never;
export declare type ConstructorParams<Actual> = Actual extends new (...args: infer P) => any ? Actual extends new () => any ? P | [] : P : never;
declare type MismatchArgs<B extends boolean, C extends boolean> = Eq<B, C> extends true ? [] : [never];

@@ -28,3 +29,3 @@ export interface ExpectTypeOf<Actual, B extends boolean> {

toBeBoolean: (...MISMATCH: MismatchArgs<Extends<Actual, boolean>, B>) => true;
toBeSymbol: (...MISMATCH: MismatchArgs<Extends<Actual, Symbol>, B>) => true;
toBeSymbol: (...MISMATCH: MismatchArgs<Extends<Actual, symbol>, B>) => true;
toBeNull: (...MISMATCH: MismatchArgs<Extends<Actual, null>, B>) => true;

@@ -36,5 +37,7 @@ toBeUndefined: (...MISMATCH: MismatchArgs<Extends<Actual, undefined>, B>) => true;

toBeCallableWith: B extends true ? (...args: Params<Actual>) => true : never;
toBeConstructibleWith: B extends true ? (...args: ConstructorParams<Actual>) => true : never;
toHaveProperty: <K extends string>(key: K, ...MISMATCH: MismatchArgs<Extends<K, keyof Actual>, B>) => K extends keyof Actual ? ExpectTypeOf<Actual[K], B> : true;
parameter<K extends keyof Params<Actual>>(number: K): ExpectTypeOf<Params<Actual>[K], B>;
parameter: <K extends keyof Params<Actual>>(number: K) => ExpectTypeOf<Params<Actual>[K], B>;
parameters: ExpectTypeOf<Params<Actual>, B>;
constructorParameters: ExpectTypeOf<ConstructorParams<Actual>, B>;
returns: Actual extends (...args: any[]) => infer R ? ExpectTypeOf<R, B> : never;

@@ -41,0 +44,0 @@ resolves: Actual extends PromiseLike<infer R> ? ExpectTypeOf<R, B> : never;

@@ -18,3 +18,3 @@ "use strict";

exports.expectTypeOf = (actual) => {
const nonFunctionProperties = ['parameters', 'returns', 'resolves', 'not', 'items'];
const nonFunctionProperties = ['parameters', 'returns', 'resolves', 'not', 'items', 'constructorParameters'];
const obj = {

@@ -37,2 +37,3 @@ toBeAny: fn,

toBeCallableWith: fn,
toBeConstructibleWith: fn,
toHaveProperty: exports.expectTypeOf,

@@ -39,0 +40,0 @@ parameter: exports.expectTypeOf,

{
"name": "expect-type",
"version": "0.5.5",
"version": "0.6.0",
"repository": "https://github.com/mmkal/ts",

@@ -14,8 +14,10 @@ "homepage": "https://github.com/mmkal/ts/tree/master/packages/expect-type#readme",

"typescript",
"validation",
"inference",
"type-check",
"assert",
"types",
"runtime"
"typings",
"test",
"testing"
],
"gitHead": "767862ae6f57e62601922d803e8fd711a993fc39"
"gitHead": "cc73488b05d18d73c7483746aead473db1179c56"
}

@@ -159,2 +159,13 @@ # expect-type

Assert on constructor parameters:
```typescript
expectTypeOf(Date).toBeConstructibleWith('1970')
expectTypeOf(Date).toBeConstructibleWith(0)
expectTypeOf(Date).toBeConstructibleWith(new Date())
expectTypeOf(Date).toBeConstructibleWith()
expectTypeOf(Date).constructorParameters.toEqualTypeOf<[] | [string | number | Date]>()
```
Promise resolution types can be checked with `.resolves`:

@@ -179,3 +190,3 @@

const thrower = () => {
throw Error()
throw Error('oh no')
}

@@ -182,0 +193,0 @@

@@ -85,2 +85,11 @@ import {expectTypeOf} from '..'

test('Assert on constructor parameters', () => {
expectTypeOf(Date).toBeConstructibleWith('1970')
expectTypeOf(Date).toBeConstructibleWith(0)
expectTypeOf(Date).toBeConstructibleWith(new Date())
expectTypeOf(Date).toBeConstructibleWith()
expectTypeOf(Date).constructorParameters.toEqualTypeOf<[] | [string | number | Date]>()
})
test('Promise resolution types can be checked with `.resolves`', () => {

@@ -99,3 +108,3 @@ const asyncFunc = async () => 123

const thrower = () => {
throw Error()
throw Error('oh no')
}

@@ -102,0 +111,0 @@

@@ -0,1 +1,2 @@

/* eslint-disable @typescript-eslint/no-unused-vars */
export type Not<T extends boolean> = T extends true ? false : true

@@ -25,3 +26,8 @@ export type Or<Types extends boolean[]> = Types[number] extends false ? false : true

export type Params<Actual> = Actual extends (...args: infer P) => any ? P : [never]
export type Params<Actual> = Actual extends (...args: infer P) => any ? P : never
export type ConstructorParams<Actual> = Actual extends new (...args: infer P) => any
? Actual extends new () => any
? P | []
: P
: never

@@ -40,3 +46,3 @@ type MismatchArgs<B extends boolean, C extends boolean> = Eq<B, C> extends true ? [] : [never]

toBeBoolean: (...MISMATCH: MismatchArgs<Extends<Actual, boolean>, B>) => true
toBeSymbol: (...MISMATCH: MismatchArgs<Extends<Actual, Symbol>, B>) => true
toBeSymbol: (...MISMATCH: MismatchArgs<Extends<Actual, symbol>, B>) => true
toBeNull: (...MISMATCH: MismatchArgs<Extends<Actual, null>, B>) => true

@@ -48,2 +54,3 @@ toBeUndefined: (...MISMATCH: MismatchArgs<Extends<Actual, undefined>, B>) => true

toBeCallableWith: B extends true ? (...args: Params<Actual>) => true : never
toBeConstructibleWith: B extends true ? (...args: ConstructorParams<Actual>) => true : never
toHaveProperty: <K extends string>(

@@ -53,4 +60,5 @@ key: K,

) => K extends keyof Actual ? ExpectTypeOf<Actual[K], B> : true
parameter<K extends keyof Params<Actual>>(number: K): ExpectTypeOf<Params<Actual>[K], B>
parameter: <K extends keyof Params<Actual>>(number: K) => ExpectTypeOf<Params<Actual>[K], B>
parameters: ExpectTypeOf<Params<Actual>, B>
constructorParameters: ExpectTypeOf<ConstructorParams<Actual>, B>
returns: Actual extends (...args: any[]) => infer R ? ExpectTypeOf<R, B> : never

@@ -76,3 +84,3 @@ resolves: Actual extends PromiseLike<infer R> ? ExpectTypeOf<R, B> : never

export const expectTypeOf = <Actual>(actual?: Actual): ExpectTypeOf<Actual, true> => {
const nonFunctionProperties = ['parameters', 'returns', 'resolves', 'not', 'items'] as const
const nonFunctionProperties = ['parameters', 'returns', 'resolves', 'not', 'items', 'constructorParameters'] as const
type Keys = keyof ExpectTypeOf<any, any>

@@ -98,2 +106,3 @@

toBeCallableWith: fn,
toBeConstructibleWith: fn,
toHaveProperty: expectTypeOf,

@@ -100,0 +109,0 @@ parameter: expectTypeOf,

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc