Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { compose, map, predicate, string } from 'decoders';
// $ExpectType Decoder
map(string, parseFloat);
// $ExpectType Decoder
compose(
string,
predicate(s => s.startsWith('x'), 'Must start with x')
);
const a = predicate((foo): foo is string => typeof foo === 'string', 'Is string');
// $ExpectType Decoder
a;
const b = predicate((foo: string): foo is 'a'|'b' => foo === 'a' || foo === 'b', 'Is a or b');
// $ExpectType Decoder<"a" | "b", string>
b;
// $ExpectType Decoder<"a" | "b", unknown>
compose(a, b);
import { compose, map, predicate, string } from 'decoders';
// $ExpectType Decoder
map(string, parseFloat);
// $ExpectType Decoder
compose(
string,
predicate(s => s.startsWith('x'), 'Must start with x')
);
const a = predicate((foo): foo is string => typeof foo === 'string', 'Is string');
// $ExpectType Decoder
a;
const b = predicate((foo: string): foo is 'a'|'b' => foo === 'a' || foo === 'b', 'Is a or b');
// $ExpectType Decoder<"a" | "b", string>
b;
// $ExpectType Decoder<"a" | "b", unknown>
compose(a, b);
import { compose, map, predicate, string } from 'decoders';
// $ExpectType Decoder
map(string, parseFloat);
// $ExpectType Decoder
compose(
string,
predicate(s => s.startsWith('x'), 'Must start with x')
);
const a = predicate((foo): foo is string => typeof foo === 'string', 'Is string');
// $ExpectType Decoder
a;
const b = predicate((foo: string): foo is 'a'|'b' => foo === 'a' || foo === 'b', 'Is a or b');
// $ExpectType Decoder<"a" | "b", string>
b;
// $ExpectType Decoder<"a" | "b", unknown>
compose(a, b);
guard(
object({
a0: string,
a1: number,
a2: optional(nullable(either4(string, email, regex(/x/, 'Must be x'), url()))),
a3: fail('foo'),
a4: maybe(mixed),
a5: either3(constant('foo'), constant('bar'), constant('qux')),
a6: exact({ c: array(poja), d: pojo }),
a7: tuple6(hardcoded('foo'), mixed, null_, undefined_, unknown, truthy),
a8: tuple4(integer, number, positiveInteger, positiveNumber),
a9: either(boolean, numericBoolean),
b0: map(
compose(
string,
predicate(s => s.startsWith('x'), 'Must start with x')
),
s => s.toUpperCase()
),
b1: shape,
b2: date,
b3: dict(string),
b4: mapping(string),
b5: oneOf(['foo', 'bar']),
b6: instanceOf(TypeError),
}),
{ style: 'simple' }
)('blah');