Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Mar 15, 2019
0 parents commit 3985e3e
Show file tree
Hide file tree
Showing 11 changed files with 6,950 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EditorConfig is awesome: http://EditorConfig.org

root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
npm-debug.log
coverage/
node_modules/
dist/
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sudo: false
language: node_js

notifications:
email:
on_success: never
on_failure: change

node_js:
- "6"
- "stable"

after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 Blake Embrey ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# TS Expect

[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]

> Checks TypeScript types match expected values.
**Why?** This is useful for designing type assertions against the TypeScript compiler. It allows you to catch a subset of issues in the compiler before runtime.

## Installation

```sh
npm install ts-expect --save
```

## Usage

```ts
import { expectType, TypeOf } from "ts-expect";

expectType<string>(123); // Compiler error!
```

### Examples

```ts
export Type = "foo" | "bar";

function validateType(type: string): type is Type {
if (type === 'foo') {
expectType<TypeOf<typeof type, Type>>(true); // Compiler error! Forgot `type === "bar"`.
return true;
}

return false;
}

function doSomething(type: Type) {
if (type === 'foo') {
return; // Do something with `foo`.
}

expectType<never>(type); // Compiler error! Forgot `type === "bar"`.

throw new TypeError(`Unknown type: ${type}`)
}
```

## License

MIT

[npm-image]: https://img.shields.io/npm/v/ts-expect.svg?style=flat
[npm-url]: https://npmjs.org/package/ts-expect
[downloads-image]: https://img.shields.io/npm/dm/ts-expect.svg?style=flat
[downloads-url]: https://npmjs.org/package/ts-expect
[travis-image]: https://img.shields.io/travis/TypeStrong/ts-expect.svg?style=flat
[travis-url]: https://travis-ci.org/TypeStrong/ts-expect
[coveralls-image]: https://img.shields.io/coveralls/TypeStrong/ts-expect.svg?style=flat
[coveralls-url]: https://coveralls.io/r/TypeStrong/ts-expect?branch=master
Loading

0 comments on commit 3985e3e

Please sign in to comment.