Skip to main content

avoid-unnecessary-nullable-return-type

added in: 1.0.0
🛠
preset: recommended

Warns when the return type of a function or a method is declared nullable, but the function or method always return non-nullable value.

Example

❌ Bad:

const value = '123';

// LINT
String? function() {
return 'srt';
}

// LINT
String? function1() {
return value;
}

// LINT
String? function2() {
return nonNullable();
}

✅ Good:

const value = '123';

String function() {
return 'srt';
}

String function1() {
return value;
}

String function2() {
return nonNullable();
}