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.11.0 to 0.12.0

10

CHANGELOG.json

@@ -7,3 +7,3 @@ {

"tag": "expect-type_v0.11.0",
"date": "Wed, 09 Dec 2020 13:25:18 GMT",
"date": "Tue, 29 Jun 2021 08:48:24 GMT",
"comments": {

@@ -13,3 +13,11 @@ "minor": [

"comment": "Add `.exclude` and `.extract` helpers (#220)"
},
{
"comment": "feat(expect-type): add `guards` & `asserts` getters (#231) - @GerkinDev"
}
],
"patch": [
{
"comment": "chore(deps): update devdependencies (#203) - @renovate[bot]"
}
]

@@ -16,0 +24,0 @@ }

9

CHANGELOG.md
# Change Log - expect-type
This log was last generated on Wed, 09 Dec 2020 13:25:18 GMT and should not be manually modified.
This log was last generated on Tue, 29 Jun 2021 08:48:24 GMT and should not be manually modified.
## 0.11.0
Wed, 09 Dec 2020 13:25:18 GMT
Tue, 29 Jun 2021 08:48:24 GMT

@@ -11,3 +11,8 @@ ### Minor changes

- Add `.exclude` and `.extract` helpers (#220)
- feat(expect-type): add `guards` & `asserts` getters (#231) - @GerkinDev
### Patches
- chore(deps): update devdependencies (#203) - @renovate[bot]
## 0.10.0

@@ -14,0 +19,0 @@ Thu, 03 Dec 2020 19:10:22 GMT

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

items: Actual extends ArrayLike<infer R> ? ExpectTypeOf<R, B> : never;
guards: Actual extends (v: any, ...args: any[]) => v is infer T ? ExpectTypeOf<T, B> : never;
asserts: Actual extends (v: any, ...args: any[]) => asserts v is infer T ? unknown extends T ? never : ExpectTypeOf<T, B> : never;
not: ExpectTypeOf<Actual, Not<B>>;

@@ -88,0 +90,0 @@ }

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

*/
exports.expectTypeOf = (actual) => {
const expectTypeOf = (actual) => {
const nonFunctionProperties = [

@@ -38,2 +38,4 @@ 'parameters',

'instance',
'guards',
'asserts',
];

@@ -68,2 +70,3 @@ const obj = {

};
exports.expectTypeOf = expectTypeOf;
//# sourceMappingURL=index.js.map
{
"name": "expect-type",
"version": "0.11.0",
"version": "0.12.0",
"keywords": [

@@ -27,3 +27,3 @@ "typescript",

"lint": "rig eslint --cache .",
"prepack": "npm run lint && rig permalink",
"prepack": "rushx lint && rig permalink",
"postpack": "rig unpermalink && git status",

@@ -30,0 +30,0 @@ "test": "rig jest"

@@ -277,2 +277,16 @@ # expect-type

You can also check type guards & type assertions:
```typescript
const assertNumber = (v: any): asserts v is number => {
if (typeof v !== 'number') {
throw new TypeError('Nope !')
}
}
expectTypeOf(assertNumber).asserts.toBeNumber()
const isString = (v: any): v is string => typeof v === 'string'
expectTypeOf(isString).guards.toBeString()
```
Assert on constructor parameters:

@@ -403,2 +417,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`.
- small implementation with no dependencies. <200 lines of code - [take a look!](https://github.com/mmkal/ts/tree/9688ca1/packages/expect-type/src/index.ts) (tsd, for comparison, is [2.6MB](https://bundlephobia.com/result?p=tsd@0.13.1) because it ships a patched version of typescript).
- small implementation with no dependencies. <200 lines of code - [take a look!](https://github.com/mmkal/ts/tree/43cf60b/packages/expect-type/src/index.ts) (tsd, for comparison, is [2.6MB](https://bundlephobia.com/result?p=tsd@0.13.1) because it ships a patched version of typescript).

@@ -116,2 +116,11 @@ export type Not<T extends boolean> = T extends true ? false : true

items: Actual extends ArrayLike<infer R> ? ExpectTypeOf<R, B> : never
guards: Actual extends (v: any, ...args: any[]) => v is infer T ? ExpectTypeOf<T, B> : never
asserts: Actual extends (v: any, ...args: any[]) => asserts v is infer T
? // Guard methods `(v: any) => asserts v is T` does not actually defines a return type. Thus, any function taking 1 argument matches the signature before.
// In case the inferred assertion type `R` could not be determined (so, `unknown`), consider the function as a non-guard, and return a `never` type.
// See https://github.com/microsoft/TypeScript/issues/34636
unknown extends T
? never
: ExpectTypeOf<T, B>
: never
not: ExpectTypeOf<Actual, Not<B>>

@@ -157,2 +166,4 @@ }

'instance',
'guards',
'asserts',
] as const

@@ -159,0 +170,0 @@ type Keys = keyof ExpectTypeOf<any, any>

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 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