{"name":"expect-type","version":"0.4.1-master-2020-03-06-00-05-12.11","repository":{"type":"git","url":"git+https://github.com/mmkal/ts.git"},"homepage":"https://github.com/mmkal/ts/tree/master/packages/expect-type#readme","license":"Apache-2.0","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc -p ."},"dependencies":{"fp-ts":"^2.1.0","io-ts":"^2.0.1"},"gitHead":"b7ba300cebbe6cf58dd989c404b9a6cfd757e748","readme":"# expect-type\n\nCompile-time tests for types. Useful to make sure types don't regress into being overly-permissive as changes go in over time.\n\n<!-- codegen:start {preset: jsdoc, module: src/index.ts, export: expectTypeOf} -->\n#### [expectTypeOf](./src/index.ts#L67)\n\nSimilar to Jest's `expect`, but with type-awareness. Gives you access to a number of type-matchers that let you make assertions about the form of a reference or generic type parameter.\n\n##### Example\n\n```typescript\nexpectTypeOf({a: 1}).toMatchTypeOf({a: 2})\nexpectTypeOf({a: 1}).property('a').toBeNumber()\n```\n\nSee the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples.\n<!-- codegen:end -->\n\n## Contents\n<!-- codegen:start {preset: md-toc, minDepth: 2, maxDepth: 5} -->\n- [expectTypeOf](#expecttypeof)\n- [Contents](#contents)\n- [Installation and usage](#installation-and-usage)\n- [Documentation](#documentation)\n- [Similar projects](#similar-projects)\n<!-- codegen:end -->\n\n## Installation and usage\n\n```cli\nnpm install expect-type\n```\n\n```typescript\nimport {expectTypeOf} from 'expect-type'\n```\n\n## Documentation\n\n<!-- codegen:start {preset: jest2md, source: src/__tests__/index.test.ts} -->\nType-check object references:\n\n```typescript\nexpectTypeOf({a: 1}).toEqualTypeOf({a: 1})\nexpectTypeOf({a: 1, b: 1}).toMatchTypeOf({a: 1})\nexpectTypeOf({a: 1}).toEqualTypeOf({a: 2})\n```\n\nAssertions can be inverted:\n\n```typescript\nexpectTypeOf({a: 1}).not.toMatchTypeOf({b: 1})\n```\n\nCatch any/unknown/never types:\n\n```typescript\nexpectTypeOf<unknown>().toBeUnknown()\nexpectTypeOf<any>().toBeAny()\nexpectTypeOf<never>().toBeNever()\n```\n\nTest for basic javascript types:\n\n```typescript\nexpectTypeOf(() => 1).toBeFunction()\nexpectTypeOf({}).toBeObject()\nexpectTypeOf([]).toBeArray()\nexpectTypeOf('').toBeString()\nexpectTypeOf(1).toBeNumber()\nexpectTypeOf(true).toBeBoolean()\nexpectTypeOf(Promise.resolve(123)).resolves.toBeNumber()\nexpectTypeOf(Symbol(1)).toBeSymbol()\n```\n\nNullable types:\n\n```typescript\nexpectTypeOf(undefined).toBeUndefined()\nexpectTypeOf(undefined).toBeNullable()\nexpectTypeOf(undefined).not.toBeNull()\n\nexpectTypeOf(null).toBeNull()\nexpectTypeOf(null).toBeNullable()\nexpectTypeOf(null).not.toBeUndefined()\n\nexpectTypeOf<1 | undefined>().toBeNullable()\nexpectTypeOf<1 | null>().toBeNullable()\nexpectTypeOf<1 | undefined | null>().toBeNullable()\n```\n\nAssertions can be inverted with `.not`:\n\n```typescript\nexpectTypeOf(1).not.toBeUnknown()\nexpectTypeOf(1).not.toBeAny()\nexpectTypeOf(1).not.toBeNever()\nexpectTypeOf(1).not.toBeNull()\nexpectTypeOf(1).not.toBeUndefined()\nexpectTypeOf(1).not.toBeNullable()\n```\n\nMake assertions about object properties:\n\n```typescript\nconst obj = {a: 1, b: ''}\n\nexpectTypeOf(obj)\n  .property('a')\n  .toEqualTypeOf(1)\nexpectTypeOf(obj)\n  .property('b')\n  .toEqualTypeOf<string>()\n```\n\nAssert on function parameters (using `.parameter(n)` or `.parameters`) and return values (using `.return`):\n\n```typescript\nconst f = (a: number) => [a, a]\n\nexpectTypeOf(f).toBeFunction()\n\nexpectTypeOf(f).toBeCallableWith(1)\nexpectTypeOf(f).not.toBeAny()\nexpectTypeOf(f).returns.not.toBeAny()\nexpectTypeOf(f).returns.toEqualTypeOf([1, 2])\nexpectTypeOf(f).returns.toEqualTypeOf([1, 2, 3])\nexpectTypeOf(f)\n  .parameter(0)\n  .not.toEqualTypeOf('1')\nexpectTypeOf(f)\n  .parameter(0)\n  .toEqualTypeOf(1)\nexpectTypeOf(1)\n  .parameter(0)\n  .toBeNever()\n\nconst twoArgFunc = (a: number, b: string) => ({a, b})\n\nexpectTypeOf(twoArgFunc).parameters.toEqualTypeOf<[number, string]>()\n```\n\nPromise resolution types can be checked with `.resolves`:\n\n```typescript\nconst asyncFunc = async () => 123\n\nexpectTypeOf(asyncFunc).returns.resolves.toBeNumber()\n```\n\nArray items can be checked with `.items`:\n\n```typescript\nexpectTypeOf([1, 2, 3]).items.toBeNumber()\nexpectTypeOf([1, 2, 3]).items.not.toBeString()\n```\n\nCheck that functions never return:\n\n```typescript\nconst thrower = () => {\n  throw Error()\n}\n\nexpectTypeOf(thrower).returns.toBeNever()\n```\n\nGenerics can be used rather than references:\n\n```typescript\nexpectTypeOf<{a: number; b?: number}>().not.toEqualTypeOf<{a: number}>()\nexpectTypeOf<{a: number; b?: number | null}>().not.toEqualTypeOf<{a: number; b?: number}>()\nexpectTypeOf<{a: number; b?: number | null}>().toEqualTypeOf<{a: number; b?: number | null}>()\n```\n<!-- codegen:end -->\n\n## Similar projects\n\nOther projects with similar goals:\n\n- [`ts-expect`](https://github.com/TypeStrong/ts-expect) exports several generic helper types to perform type assertions\n- [`dtslint`](https://github.com/Microsoft/dtslint) does type checks via comment directives and tslint\n- [`tsd-check`](https://github.com/SamVerschueren/tsd-check/issues/10) is a CLI that runs the TypeScript type checker over assertions\n- [`type-plus`](https://github.com/unional/type-plus) comes with various type and runtime TypeScript assertions\n- [`static-type-assert`](https://github.com/ksxnodemodules/static-type-assert) type assertion functions\n","readmeFilename":"readme.md","description":"Compile-time tests for types. Useful to make sure types don't regress into being overly-permissive as changes go in over time.","bugs":{"url":"https://github.com/mmkal/ts/issues"},"_id":"expect-type@0.4.1-master-2020-03-06-00-05-12.11","_nodeVersion":"12.16.1","_npmVersion":"lerna/3.18.1/node@v12.16.1+x64 (linux)","dist":{"integrity":"sha512-OAf2fZ9LFhQ5MjMsLLghAwvJPuWTHdyV6azNkd7niGBC+bLL5oUXVLdiPLH395U3KORabxQErJL1IIaXLSs0eQ==","shasum":"0b47578f4861a388337753f1e94e5cd6e67eb2bc","tarball":"http://registry-npm.ywwl.com/expect-type/download/expect-type-0.4.1-master-2020-03-06-00-05-12.11.tgz","fileCount":21,"unpackedSize":190493,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeYdpkCRA9TVsSAnZWagAAqqUP/imBTXK9tTUAGz2+bTsN\nLfKT+b0xohresMzATlSzN5n13JCa93Hk8mC7gIZr69nDqXIHafsYj7f1RuZv\nwXV8XBoVVawIZmqBLIb5OrWNszH7XvRLywI0JP4z5gl2l8p8xOoZsa2C+b5j\nyMG0remCLceXQ0iHsGZTNSat+xhLZhInoiWodMwkdmYY+hB6O4JfCNpni6yM\n2n0FOcacL9RPBrwZXAtmEnYSpyj16+w84cB8BKx84xzJqi16Zk8nN1uDRYDD\n4l/eyjQhRJRe/YRl3snEohgQdNruZrptZVt7LuxVraeiCEuHxypaNQJOpALm\nmPlupYhWaGBNQRYxBzsBiwjAJSPrpx6PbntxfM//OnV4SLLGYbl0DBCJOKrJ\n13feZQ8b8yibcyfWaSiJ0zWGXxzw/zH5TRVFjDRyfzvyoggvkOk7/Ie5lv/X\n9HvLQ9xcX1zlgu0N3xZQ4zn4T2qQf/d6H4n0MhePo/VPzK1FBrrPzuv56o+N\nKI20RIfb8m9pYwsI9JYYywPlU6Yz96lxbdUKdIV7HdShzRG5gSaxKM4rqeNI\nkpDOvZ0Ww04UviDTC9RBzG+6gZ7o5K/x4/AAkHoPBc61s+qDFHNeNf0TUJ6W\nNngRKZPak6aXNNL6BV4AzNtr0AIz7tNIhdKKlLTGlqq8AcyxzSu382fVUcKe\nA3bz\r\n=mkkL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIForaM+/ZoPLWaalwpzY3m7y+9gADJpBDHK1ZEvV+36GAiEA/lBAJM8wPMRdDTLQVCSGKZl/hl6g/n+LTSyMjPJk9b4="}],"size":23609,"noattachment":false,"key":"/expect-type/-/expect-type-0.4.1-master-2020-03-06-00-05-12.11.tgz"},"maintainers":[{"name":"mmkal","email":"mmkal1@outlook.com"}],"_npmUser":{"name":"mmkal","email":"mmkal1@outlook.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/expect-type_0.4.1-master-2020-03-06-00-05-12.11_1583471203875_0.24217733686382803"},"_hasShrinkwrap":false,"publish_time":1583471203994,"_cnpm_publish_time":1583471203994,"dist-tags":{"latest":"1.4.0","master":"0.4.1-master-2020-03-06-00-05-12.11","next":"1.0.0-rc.0"}}