While using the json runtype for the first time lately, I noticed that, while the runtype was working in terms of producing the correct output, it was losing type information. For example, after adding the tests from this PR, but before changing anything in src/json.ts, if I ran yarn test:types I got the following output:
output
```
❯ yarn run test:types
yarn run v1.22.19
$ tsd
test-d/json.test-d.ts:11:21
✖ 11:21 Argument of type unknown is not assignable to parameter of type number.
✖ 16:21 Argument of type unknown is not assignable to parameter of type string.
✖ 21:23 Argument of type unknown is not assignable to parameter of type number[].
✖ 26:28 Argument of type unknown is not assignable to parameter of type { a: string; }.
test-d/record.test-d.ts:51:57
✖ 51:57 Argument of type { a: string; b: unknown; d: string; } is not assignable to parameter of type { a: string; b: { c: string; }; d: string; }.
Types of property b are incompatible.
Type unknown is not assignable to type { c: string; }.
5 errors
error Command failed with exit code 1.
```
And in VS Code I can see the following in the json tests that already exist in test/json.test.ts:
Reproduction of issue: codesandbox.io
While using the
json
runtype for the first time lately, I noticed that, while the runtype was working in terms of producing the correct output, it was losing type information. For example, after adding the tests from this PR, but before changing anything insrc/json.ts
, if I ranyarn test:types
I got the following output:output
``` ❯ yarn run test:types yarn run v1.22.19 $ tsd test-d/json.test-d.ts:11:21 ✖ 11:21 Argument of type unknown is not assignable to parameter of type number. ✖ 16:21 Argument of type unknown is not assignable to parameter of type string. ✖ 21:23 Argument of type unknown is not assignable to parameter of type number[]. ✖ 26:28 Argument of type unknown is not assignable to parameter of type { a: string; }. test-d/record.test-d.ts:51:57 ✖ 51:57 Argument of type { a: string; b: unknown; d: string; } is not assignable to parameter of type { a: string; b: { c: string; }; d: string; }. Types of property b are incompatible. Type unknown is not assignable to type { c: string; }. 5 errors error Command failed with exit code 1. ```And in VS Code I can see the following in the
json
tests that already exist intest/json.test.ts
:screenshot
![2022-08-07-11 02](https://user-images.githubusercontent.com/8270635/183273122-c57815e1-4ef1-4f98-b775-c23c48bbd8ee.png)After making this PR's changes in
src/json.ts
, the tests pass and I see the following in VS Code:screenshot
![2022-08-07-11 16](https://user-images.githubusercontent.com/8270635/183273470-f03262af-9ac6-4e96-afe9-8c856180b72f.png)