192 questions
Tooling
0 votes
2 replies
59 views
using optional chaining with === in case of both 'undefined'
I am using optional chaining quite often, but so far never encounter that issue, until today: if both items can be undefined, rather don't use optional chaining. Only last test (below) can help in ...
0 votes
0 answers
77 views
In React + TypeScript, when should a prop be prop?: Type vs prop: Type | undefined? [duplicate]
When designing TypeScript props for React components, I'm sometimes unsure whether I should type props like: prop?: Type or prop: Type | undefined My understanding so far: prop?: Type The prop ...
1 vote
1 answer
162 views
non-removable extra whitespace formatting after a colon, which creates an error in VSCode [closed]
I have this problem - I cannot use Tailwind in my project or optional chaining operator (?.) because VSCode adds an extra whitespace after a colon or after a dot. In case of taiwind, it adds a ...
0 votes
1 answer
78 views
TypeScript complains about optional chaining
I am using TypeScript 5.7.3. Installed @types/[email protected]. TypeScript config: { "compilerOptions": { "target": "ES2020", "moduleResolution": &...
4 votes
2 answers
258 views
Angular typescript error with BigInt and Optional Chaining, nullish coalescing
We have an application that needs to be supported in old Chrome (v79). Angular Version 13.2.7 Typescript Version 4.5.5 Node Version 16.14.0 We are getting an error: ERROR: Big integer literals are not ...
1 vote
2 answers
96 views
How can I log a value in a Java Optional.of chain? [duplicate]
I'm using an Optional.of chain in Java to get a value, Integer yearOfBirth = Optional.ofNullable(employee) .map(Employee::getDateOfBirth) ....
-6 votes
1 answer
164 views
$_POST variable from request contains optional instead of string in PHP [closed]
The use case is a user/client sends a request to a server running PHP. I am trying to write the PHP code on the server e.g. an API endpoint to process the request. I have existing production PHP code ...
8 votes
6 answers
2k views
C++ equivalent of Javascript's '?.' operator for optional-chaining?
In Javascript, if I have a potentially null object obj, which, if not null, will have a field x - I can write obj?.x. This is called "optional chaining" or "safe navigation": If ...
0 votes
1 answer
390 views
How to implement Optional chaining in ngModel using angular 18
I have scenario in my project that a common shared service having a common variable (object) to store nested objects. I have to access and update its value in html using NgModel. Optional-chaining ...
0 votes
1 answer
121 views
Using nullable objects in Optional methods after covering it with ofNullable
I came across the below code: public void method(MyObject obj) { String value = Optional.ofNullable(obj) .map(x -> obj.doSomething()) ....
0 votes
1 answer
173 views
Optional's orElse() executed even when object is present [duplicate]
I've encountered an unexpected behavior while using the Optional API in Java. Session session = sessionService .getSessionById(id) .orElse( ...
0 votes
1 answer
172 views
VSCode IntelliSense displaying an error on Optional Chaining in TypeScript
In VSCode, IntelliSense is saying a property does not exist on an object in a TypeScript file even when I specify the optional chaining syntax to short-circuit the error. The code compiles correctly ...
1 vote
1 answer
88 views
How to turn a optional of an string array into a optional of a string?
I struggle with finding an elegant way to convert a variable of type Optional<String[]> to Optional<String> and joining all elements of the given array. Is there an elegant solution for ...
0 votes
0 answers
138 views
Is there a shorter way to tell Mypy that a given optional chaining is fine?
I am working on Python code where the domain logic makes it natural to have a class with an optional field of a second class, which itself has an optional field of a third class. Boiling it down to a ...
2 votes
2 answers
256 views
Why does optional-chaining multiple property accesses throw for an empty object, but not for null?
in a node repl or browser console: > ({})?.a undefined > (null)?.a undefined > (null)?.a.b undefined > ({})?.a.b Uncaught TypeError: Cannot read properties of undefined (reading 'b') if (...