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

Is the "required" keyword really necessary with non nullable types? #1502

Closed
LasseRosenow opened this issue Mar 8, 2021 · 1 comment
Closed
Labels
feature Proposed language feature that solves one or more problems

Comments

@LasseRosenow
Copy link

LasseRosenow commented Mar 8, 2021

if we have a method that has parameters with labels, by default they would be optional, so if they are not specified when the method is called, they would be null.

To also have parameters with labels that are not optional there is the required keyword.

But since non nullability is a thing in dart, a labeled parameter needs to either be nullable without a required keyword or be non nullable and have the required keyword.

But if a parameter is non nullable it is theoretically implicitly required so having the required keyword seems to be very unnecessary In my opinion. And I think the language would be much cleaner without it.

Code example for required labeled parameters:

// Current required
void foo({required String bar});

// Proposed required
void foo({String bar});

// Optional stays the same:
void foo({String? bar});
@LasseRosenow LasseRosenow added the feature Proposed language feature that solves one or more problems label Mar 8, 2021
@LasseRosenow
Copy link
Author

Closing this as it's a duplicate of #878

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

1 participant