deepkit / deepkit-framework

A new full-featured and high-performance TypeScript framework
https://deepkit.io/
MIT License
3.18k stars 121 forks source link

Extending an omitted interface doesn't work #464

Closed marcus-sa closed 11 months ago

marcus-sa commented 1 year ago
import { ReflectionClass, typeOf, validate } from '@deepkit/type';

test('validate omitted extended interfaces', () => {
  interface A {
    readonly a: string;
    readonly value: string;
  }

  interface B extends Omit<A, 'value'> {
    readonly b: string;
  }

  const type = typeOf<B>();
  console.log(validate({ b: '' }, type)); // []
  console.log(ReflectionClass.from(type).getPropertyNames()); // [ 'b' ]
});
marcus-sa commented 1 year ago

Interesting, Omit doesn't work with referenced types:

import { typeOf, validate } from '@deepkit/type';

test('validate nested interfaces', () => {
  interface A {
    readonly a: string;
    readonly value: string;
  };

  type B = Omit<A, 'value'>;

  const type = typeOf<B>();
  console.log(validate({}, type)); // []
});

It only works for inline types https://github.com/deepkit/deepkit-framework/blob/3fd48ea79d807410412f84d1bfd3010b8f5bbefe/packages/type/tests/standard-functions.spec.ts#L42-L45

marcus-sa commented 1 year ago

Pick only works for inline types as well.

marcj commented 11 months ago

weird, works for me. Added also a test that shows Omit works with non-inline types: https://github.com/deepkit/deepkit-framework/commit/a47111c53f43ceb11cbbf4f4fb72c8d72eac9507

marcus-sa commented 11 months ago

weird, works for me. Added also a test that shows Omit works with non-inline types: a47111c

I assume it's because my typescript target was set to esnext.

marcus-sa commented 11 months ago

weird, works for me. Added also a test that shows Omit works with non-inline types: a47111c

I assume it's because my typescript target was set to esnext.

@marcj yeah it works fine when it's set to es2022. @typescript/vfs is bugged and doesn't return the correct lib files for esnext.