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

CopyWith on records #81

Open
Maksimka101 opened this issue Apr 25, 2023 · 4 comments · May be fixed by #83
Open

CopyWith on records #81

Maksimka101 opened this issue Apr 25, 2023 · 4 comments · May be fixed by #83
Labels
enhancement New feature or request

Comments

@Maksimka101
Copy link

Records are coming in the dart 3. They are pretty useful and the almost only drawback is the inability to copy them. I believe it's possible to implement as records can have extensions

So I imagine this api:

@copyWith
typedef User = ({
  String id,
  String name,
});

void main() {
  final User user1 = (id: 'id', name: 'name');
  final User user2 = user1.copyWith(id: 'id2');
}
@numen31337
Copy link
Owner

If I'm not mistaken, according to the feature specification a Record can't be extended as per:

The type Record refers to a built-in class defined in dart:core. It has no instance members except those inherited from Object and exposes no constructors. It can't be constructed, extended, mixed in, or implemented by user-defined classes.

It might be a useful feature, but apparently we can't implement it here. Please let me know if I'm missing something.

@numen31337 numen31337 added the question Further information is requested label Jun 11, 2023
@Maksimka101
Copy link
Author

As you can see, It is possible to create an extension on a record:

image

Sorry for screenshot

@Maksimka101
Copy link
Author

Btw, I have an experience with code generation. So can't guarantee anything, but probably I can try to implement it if you are too busy

@numen31337
Copy link
Owner

I'm going to have a look at it. Not sure about the timing tho.

@numen31337 numen31337 added enhancement New feature or request and removed question Further information is requested labels Jun 13, 2023
@numen31337 numen31337 linked a pull request Jun 13, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants