ostrowr / ts-json-validator

Let JSON play nicely with Typescript
MIT License
342 stars 7 forks source link

improvement: change validate from an assertion function to a type guard #13

Closed ostrowr closed 5 years ago

ostrowr commented 5 years ago

Usage of parser.validate is unclear because you need to assign an output type, which defeats the purpose of this whole library (see https://github.com/microsoft/TypeScript/issues/34596 and related issues.) This changes .validate (which throws on invalid input) to .validates, which is a type guard that returns false on invalid input. .parse still throws on invalid input.

BREAKING CHANGE: TsjsonParser.validate renamed to TsjsonParser.validates and functionality changed from assertion function to type guard.

This fixes the issue in the discussion of from https://github.com/ostrowr/ts-json-validator/issues/10

codecov[bot] commented 5 years ago

Codecov Report

Merging #13 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #13   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines          21     24    +3     
  Branches        2      3    +1     
=====================================
+ Hits           21     24    +3
Impacted Files Coverage Δ
src/tsjson-parser.ts 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bad212a...dddc840. Read the comment docs.