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

feat: support class member type infer #2794

Closed

Conversation

HerrCai0907
Copy link
Member

Introduce new ResolvedType to make lazy type inference possible.

Copy link
Member

@CountBleck CountBleck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the compiler requires an AST node somewhere because, minus the requirement in the parser, the root of this issue is program.ts:3995 and program.ts:4009.

Here, stub getter/setter declarations are made with the type node from the field declaration, and the compiler has no way to obtain the initializer or its true type when the getter/setter is resolved. So some sort of hack (like this) is necessary (or a big refactor for type resolution).

By the way, does the following (using generic type parameters in initializers) work?

class Box<T> { value: T | null = null; }
class Example<T> {
    blaBlaBla = new Box<T>();
}

@HerrCai0907
Copy link
Member Author

HerrCai0907 commented Nov 15, 2023

So some sort of hack (like this) is necessary (or a big refactor for type resolution).

Agree. I don't want to refactor the whole type resolution at this time.

@HerrCai0907
Copy link
Member Author

HerrCai0907 commented Nov 15, 2023

By the way, does the following (using generic type parameters in initializers) work?

class Box<T> { value: T | null = null; }
class Example<T> {
    blaBlaBla = new Box<T>();
}

Not support yet since we don't have flow in Class. So we can only use file's flow now.

@HerrCai0907
Copy link
Member Author

This is not a good implement, it introduces new AST node, but still cannot cover all cases. I need to think about it again.

@HerrCai0907 HerrCai0907 deleted the class-member-initializer branch November 23, 2023 22:58
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

Successfully merging this pull request may close these issues.

None yet

2 participants