ostrowr/ts-json-validator

Bug: type checking via `Validated` is not working as expected

cogell opened this issue · 2 comments

See the following small example of the error:

import { createSchema as S, Validated } from 'ts-json-validator';

const MySchema = S({
  type: 'object',
  properties: { field1: S({ type: 'string' }) },
  required: ['field1'],
});

// typescript thinks MySchemaType is `never` type
type MySchemaType = Validated<typeof MySchema>;

const myObj: MySchemaType = {
  // expect typescript error here
  field1: 1, 
};

https://codesandbox.io/s/modest-mccarthy-zyjdq

Thanks! I can't replicate this on 3.7.x – unfortunately, this library depends on some recursive type shenanigans that don't work until 3.7. Closing for now but feel free to reopen if (a) you have any ideas about how to get this working on < 3.7 or (b) you see the same issue while using Typescript 3.7+.

Oh shoot, you're right! Thanks for the help. @ostrowr 🙇‍♂️

For anyone else running into this, VSCode does NOT automatically use your locally installed typescript version. To set your VSCode workspace to use local typescript see this stackoverflow answer: https://stackoverflow.com/a/39676463/1873778