Skip to content

Commit

Permalink
fix: use null instead of unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
runeh committed Apr 28, 2021
1 parent 968bb51 commit 030fa56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ describe('json-to-runtypes', () => {
jsonToRuntypes({
name: 'rune',
age: 41,
tags: ['foo', 'bar', 'baz'],
tokens: [],
posts: [
{ title: 'intro', published: true },
{ title: 'chapter-1', editorApproved: true },
{ title: 'intro', published: true, tags: ['foo', 'bar', 'baz'] },
{ title: 'chapter-1', editorApproved: true, tags: [] },
{
title: 'chapter-2',
heroImage: {
Expand All @@ -31,6 +31,7 @@ describe('json-to-runtypes', () => {
rt
.Record({
published: rt.Boolean,
tags: rt.Array(rt.String),
editorApproved: rt.Boolean,
heroImage: HeroImageRt,
})
Expand All @@ -42,7 +43,7 @@ describe('json-to-runtypes', () => {
export const RootRt = rt.Record({
name: rt.String,
age: rt.Number,
tags: rt.Array(rt.String),
tokens: rt.Array(rt.Never),
posts: rt.Array(PostsRt),
});
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import { AnyType as InAnyType, guess } from 'guess-json-shape';

function guessTypeToRuntypDef(inType: InAnyType): OutAnyType {
switch (inType.kind) {
case 'primitive': {
const t = inType.type === 'null' ? 'unknown' : inType.type;
return { kind: t };
}
case 'primitive':
return { kind: inType.type };

case 'named':
return { kind: 'named', name: inType.name };
Expand Down

0 comments on commit 030fa56

Please sign in to comment.