Skip to content

Commit

Permalink
feat: Add null and undefined types #64
Browse files Browse the repository at this point in the history
  • Loading branch information
runeh committed Apr 27, 2021
1 parent a5ad6d3 commit ac8be76
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('runtype generation', () => {
{ name: 'someString', type: { kind: 'string' } },
{ name: 'someSymbol', type: { kind: 'symbol' } },
{ name: 'someUnknown', type: { kind: 'unknown' } },
{ name: 'someNull', type: { kind: 'null' } },
{ name: 'someUndefined', type: { kind: 'undefined' } },
{
name: 'someLiteral1',
type: { kind: 'literal', value: 'string' },
Expand Down Expand Up @@ -113,6 +115,8 @@ describe('runtype generation', () => {
someString: rt.String,
someSymbol: rt.Symbol,
someUnknown: rt.Unknown,
someNull: rt.Null,
someUndefined: rt.Undefined,
someLiteral1: rt.Literal(\\"string\\"),
someLiteral2: rt.Literal(1337),
someLiteral3: rt.Literal(true),
Expand Down Expand Up @@ -496,9 +500,11 @@ describe('runtype generation', () => {
['boolean', 'Boolean'],
['function', 'Function'],
['never', 'Never'],
['null', 'Null'],
['number', 'Number'],
['string', 'String'],
['symbol', 'Symbol'],
['undefined', 'Undefined'],
['unknown', 'Unknown'],
] as const)('generates runtype with `%s` kind', (kind, runtype) => {
const source = generateRuntypes(
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ const writers: Record<
function: simpleWriter('rt.Function'),
never: simpleWriter('rt.Never'),
number: simpleWriter('rt.Number'),
null: simpleWriter('rt.Null'),
string: simpleWriter('rt.String'),
symbol: simpleWriter('rt.Symbol'),
undefined: simpleWriter('rt.Undefined'),
unknown: simpleWriter('rt.Unknown'),
array: writeArrayType,
record: writeRecordType,
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const simpleTypeRt = rt.Record({
rt.Literal('boolean'),
rt.Literal('function'),
rt.Literal('never'),
rt.Literal('null'),
rt.Literal('number'),
rt.Literal('string'),
rt.Literal('symbol'),
rt.Literal('undefined'),
rt.Literal('unknown'),
),
});
Expand Down

0 comments on commit ac8be76

Please sign in to comment.