Skip to content

Conversation

@wwwzbwcom
Copy link

Hello, currently abstract class cant pass transformAndValidate type check.

When export declare type ClassType<T> = new (...args: any[]) => T;, abstract class validate can't pass type check.

abstract class User {
    @IsString()
    @MinLength(5)
    name: string;
}

let user: User = {
    name: 'hello'
};

transformAndValidate(User, user);

Use export type ClassType<T> = {prototype: T}; to allow check for abstract class, and plain object also cant pass check

Use `export type ClassType<T> = {prototype: T};` to allow check for abstract class
@MichalLytek MichalLytek self-requested a review November 9, 2020 09:17
@MichalLytek
Copy link
Owner

@wwwzbwcom It solves the args problem but makes an issue for the receiver - you can't do new Foo() anymore as without new signature the type with prototype is not newable.

And I think TypeScript do a good job here - abstract class in abstract, you shouldn't be able to create an instance of such class. transformAndValidate does exactly that, returning you an instance of abstract User class.

I think you should change the way you define your abstract and non-abstract classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants