Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending an omitted interface doesn't work #464

Closed
marcus-sa opened this issue Aug 1, 2023 · 5 comments
Closed

Extending an omitted interface doesn't work #464

marcus-sa opened this issue Aug 1, 2023 · 5 comments

Comments

@marcus-sa
Copy link
Contributor

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 marcus-sa changed the title Omitting extended interfaces doesn't work Extending an omitted interface doesn't work Aug 1, 2023
@marcus-sa
Copy link
Contributor Author

marcus-sa commented Aug 1, 2023

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

test('Omit', () => {
equalType<Omit<{ a: string, b: number, c: boolean }, 'b' | 'c'>, { a: string }>();
equalType<Omit<{ a: string, b: number, c: boolean }, 'a'>, { b: number, c: boolean }>();
});

@marcus-sa
Copy link
Contributor Author

marcus-sa commented Sep 1, 2023

Pick only works for inline types as well.

@marcj
Copy link
Member

marcj commented Oct 1, 2023

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

@marcus-sa
Copy link
Contributor Author

marcus-sa commented Oct 2, 2023

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants