You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement no discard error for return values #29173
Annotate function/method with nodiscard then its return value should never be discarded
Nodiscard type
Annotate class , interface ,enum ,and/or type can be annotated with nodiscard then , if any function returns value of that type ,then returned value should never be discarded
what if user wants to discard the value any way
user can use same ts-ignore override compiler error
Use Cases
If a function returns error_code programmer always need to check for errors before proceeding to next step
If a function returns Observable programmer always need to subscribe that or need call that function as Observables are evaluated only on subscribe.
Examples
This is purely conceptual (I have no idea which syntax will suit this)
Function/Method
functionsomeCalulation():ErrorCode[[nodiscard]]{}consterror=someCalculation();// good buildssomeCalculation();// compiler error return value discarded
Type
classVeryImportant[[nodiscard]]{}functionsomeCalulation():VeryImportant{}consterror=someCalculation();// good buildssomeCalculation();// compiler error return value discarded
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code (it depends on syntax which need to be decided)
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
Activity
ajafff commentedon Dec 27, 2018
Duplicate of #8240
abdulkareemnalband commentedon Dec 29, 2018
Klaus Meinhardt (@ajafff) #8240 is closed may be #8584 is more appropriate issue
also I have edited description with more search terms which i failed to add before
typescript-bot commentedon Dec 31, 2018
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.