Created
December 7, 2017 22:27
-
-
Save gunzip/b8106b31fb8eeec1e27c9ec2c2ccbfb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function withDefault<T extends t.Any>( | |
type: T, | |
defaultValue: t.TypeOf<T> | |
): t.Type<any, t.TypeOf<T>> { | |
return new t.Type( | |
type.name, | |
(v: any): v is T => type.is(v), | |
(v: any, c: any) => type.validate(v !== undefined ? v : defaultValue, c), | |
(v: any) => type.serialize(v) | |
); | |
} | |
export type TimeToLiveWithDefault = t.TypeOf<typeof TimeToLiveWithDefault>; | |
export const TimeToLiveWithDefault = withDefault(TimeToLive, 3600 as any); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment