Skip to content

Commit

Permalink
fix(generator): safely access reserved exports from io-ts
Browse files Browse the repository at this point in the history
Because of the bug in rollup rollup/rollup#2680

re #5
  • Loading branch information
Alex Malkevich committed Feb 7, 2019
1 parent 15f51d3 commit 9513f98
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion projects/gen-io-ts/src/lib/generator.ts
Expand Up @@ -4,6 +4,16 @@ import { ResolvedTypeMetadata, resolveMetadataOf } from './metadata';
import { Primitive, Type } from './types';
import { isBuiltinType, isObject, isPrimitive } from './util';

/**
* Required to safely access from `io-ts` reserved exports like `undefined`
* because of the bug in rollup
* @see https://github.com/rollup/rollup/issues/2680
* @internal
*/
function getIoTs<K extends keyof typeof t>(prop: K) {
return t[prop];
}

/**
* Generate `io-ts` codec for `type`
*
Expand All @@ -26,7 +36,7 @@ function genTypeFor(obj: any, name?: string): t.Type<any> {
}

if (metadata && !metadata.isRequired) {
codec = t.union([codec, t.null, t.undefined]);
codec = t.union([codec, getIoTs('null'), getIoTs('undefined')]);
}

return codec;
Expand Down

0 comments on commit 9513f98

Please sign in to comment.