Skip to content

Releases: woutervh-/typescript-is

v0.16.0

11 May 17:44
9f6058e

Choose a tag to compare

New Features

  • Merged PR #61 (@t-winter). The global Date class is now treated as a special case. It will in fact be checked in the generated type guard code. This even applies when ignoreClasses is set to true.
import { is } from 'typescript-is';

// Will return true:
is<Date>(new Date()); // effectively using `instanceof global.Date` or `instanceof window.Date`

// Will return false:
is<Date>({});
// used to generate error when `ignoreClasses = false`, or return true when `ignoreClasses = true`

Breaking Changes

None.

Bug fixes

None.

v0.15.0

13 Mar 15:34

Choose a tag to compare

New Features

  • Merged PR #53 (@hmil). Error messages from the assertions will now be more specific. When an identifier is used, for example in the decorators of class methods, their name will be used as the first part of the path of the error message.

Breaking Changes

None.

Bug fixes

None.

v0.14.3

06 Mar 20:10

Choose a tag to compare

New Features

None.

Breaking Changes

  • Changed the behavior of ignoreMethods to really only ignore methods. Properties of objects which are functions, and not methods, are no longer ignored by this option. Use ignoreFunctions instead. To explain the difference:
interface WithMethod {
  method(): void; // Ignored only by `ignoreMethods`.
}

interface WithFunction {
  method: () => void; // Previously ignored by `ignoreMethods`, now only ignored by `ignoreFunctions`.
}

Bug fixes

  • Fix issue #50. Added option ignoreFunctions which will cause the type guards to ignore functions.

v0.14.2

06 Mar 18:55

Choose a tag to compare

New Features

None.

Breaking Changes

None.

Bug fixes

  • Fix issue #49. When strictNullChecks is set to false in the compiler options, then validations for all the types will pass if the object is null or undefined.

v0.14.1

10 Feb 12:24

Choose a tag to compare

New Features

None.

Breaking Changes

None.

Bug fixes

  • Fixed some incorrect types in the index.d.ts file from the previous release.

v0.14.0

10 Feb 12:19

Choose a tag to compare

New Features

  • Added requested feature from #39. It is now possible to get the path to the failed validation as an array. It is also possible to get the reason of the failed validation. These are available from the error objects thrown by the assertType family of functions, as well the the decorators. Example:
try {
  assertType<{ value: number }>({ value: 'not a number' });
} catch (error) {
  if (error instanceof TypeGuardError) { // Will be true unless custom error classes are used.
    console.log(error.path); // path indicating where the validation failed: ['$', 'value']
    console.log(error.reason); // object describing the reason why the validation failed: { type: 'number' }
  }
}

Breaking Changes

  • Removed option to add a custom error message to the AssertType decorator. You can instead use the new feature described above to construct custom error messages if necessary.

Bug fixes

None.

v0.13.1

04 Dec 12:57

Choose a tag to compare

New Features

None.

Breaking Changes

None.

Bug fixes

  • Fixed issue #43. Tuples with optional type arguments are now correctly checked. For example, type X = [number, number?]; will be checked if the length is 1 <= length <= 2

v0.13.0

11 Oct 09:10

Choose a tag to compare

New Features

None.

Breaking Changes

None.

Bug fixes

  • Fixed issue #37. When you're using TypeScript version 3.0, typescript-is is no longer identifying arrays as classes.

v0.12.6

26 Sep 08:04

Choose a tag to compare

New Features

None.

Breaking Changes

None.

Bug fixes

  • Fixed issue #35. Empty tuples should now correctly be type checked without throwing an error.

v0.12.5

23 Sep 19:06

Choose a tag to compare

New Features

  • A new option to set the default implementation of the type-check function is available as setDefaultGetErrorMessage. This can be used in certain conditions where the code is not transpiled and would normally cause an error to be thrown. In this case setDefaultGetErrorMessage can be used to avoid errors. Fixes issue #33.

Breaking Changes

None.

Bug fixes

None.