optional-chaining Questions

1

As far as I know, the null safe operator doesn't work on arrays. Is there another way to achieve the same effect with array chaining? For example: $array = []; if (isset($array['a'])) { if (isset...
Khanna asked 10/11, 2021 at 21:1

3

I have an async function that returns an optional String. func traverse(file:URL, for string:String) async throws -> String? { ... } I want to run this function and if nil, run it with differen...
Fjord asked 2/8, 2021 at 16:30

4

Solved

So, I am reading optional chaining in JavaScript and a question popped into my head. Consider the code below: let person = null let street = person?.street // returns undefined My question is that...
Anthem asked 10/4, 2022 at 15:36

3

Solved

i tried to use optional chaining in javascript but my eslint rules causing error . Error : Unsafe usage of optional chaining. If it short-circuits with 'undefined' the evaluation will throw TypeErr...
Wattmeter asked 7/3, 2023 at 7:27

3

Solved

When deserializing deeply nested structures (e.g. from JSON), it's not uncommon to have to traverse multiple Option types. For example: let foo = Foo { x: Some(Bar { y: Some(Baz { z: Some(42), ...
Round asked 4/5, 2022 at 17:2

3

Solved

Is there any reason to use if to check if method exists, before calling await if (someObject.save){ await someObject.save(); } rather than using nullish coallescence diectly with await await som...
Sclerophyll asked 7/11, 2022 at 17:4

8

Solved

Is there an easy way to natively determine if a deep property exists within an object in JavaScript? For example, I need to access a property like this: var myVal = appData.foo.bar.setting; But ...
Lockman asked 3/10, 2011 at 15:1

1

I have a data structure that is deeply nested and I want to be able to reference an inner type in it, but that type doesn't have its own name/definition. For example: MyQuery['system']['errors']['l...
Pandemic asked 25/11, 2020 at 16:1

4

Solved

Project setup: Vuejs 3 Webpack 4 Babel TS We created the project using vue-cli and add the dependency to the library. We then imported a project (Vue Currency Input v2.0.0) that uses optional ...
Luminosity asked 17/6, 2021 at 9:33

1

Optional chaining isn't working on my Vue.js (v2) project on Node 14.17. const adventurer = { name: 'Alice', cat: { name: 'Dinah' } }; const dogName = adventurer.dog?.name; console.log(dogName...
Merideth asked 17/9, 2021 at 9:17

5

Solved

I'm trying to use optional chaining with an array instead of an object but not sure how to do that: Here's what I'm trying to do myArray.filter(x => x.testKey === myTestKey)?[0]. Also trying sim...

1

Solved

Coming from a background in C# the null-conditional operator allows you to call a function avoiding a possible null-reference exception like so: Func<int> someFunc = null; int? someInteger = ...
Marten asked 23/10, 2021 at 19:36

1

In the vue/vuetify project, while trying to get optional chaining (https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining) to work, I always encounter an error: ./src/App.vue?vue&t...
Genoese asked 23/12, 2020 at 16:9

1

Solved

console.log("#1", "a12312a".match(/^\d+/)?.[0].length); console.log("#2", ("a12312a".match(/^\d+/)?.[0]).length); I was writing some code and stumbled upon something I don’t understand. ...
Psychrometer asked 22/4, 2021 at 7:9

7

Solved

My problem is a general one, how to chain a series of attribute lookups when one of the intermediate ones might return None, but since I ran into this problem trying to use Beautiful Soup, I'm goin...
Kellum asked 7/3, 2013 at 19:55

2

Solved

Using optional chaining with function calls causes the expression to automatically return undefined instead of throwing an exception if the method isn't found. Note: The code is using spread synt...
Indispensable asked 13/3, 2021 at 2:46

3

Solved

Scenario: We're using webpack 4 to create a bundle from our Javascript sources. We're not using Babel because we're authoring only for a single platform (latest Chrome), and we're only using fe...
Philosophy asked 29/1, 2020 at 17:16

1

Solved

I have a response which I am accessing: data?.currentOrganization?.onboardingSteps?. As you can guess, data, currentOrganization, and onboardingSteps might all be null. I want to assign a variable ...
Mastersinger asked 2/2, 2021 at 21:31

2

Solved

TypeScript 3.7 now supports the optional chaining operator. Hence, you can write code such as: const value = a?.b?.c; I.e., you can use this operator to access properties of an object, where the o...
Aquanaut asked 9/11, 2019 at 15:42

1

Just updated to Angular 10 from 9.0 Every use of Optional Chaining (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#optional-chaining) in my code now results in its o...
Entirety asked 24/7, 2020 at 0:44

1

Vs code > OUTPUT > Prettier 2/23/2020, 12:10:36 PM: ----------------------- Expression expected. (/Users/yanivper/dev/test/test.ts:2:23) 1 | function test(obj) { 2 | return obj.a?.b; ^ In a new...
Palaeozoic asked 23/2, 2020 at 10:19

7

Solved

I've been programming a lot in Swift recently. Today I did some work in JavaScipt when question popped up to me: Is there something similar to optional chaining in JavaScript? A way to preve...
Midyear asked 3/10, 2014 at 17:39

3

Solved

Currently I am using below code for destructuring: const myObj1 = {name: 'Abc'} const {name} = myObj1 console.log(name) const myObj2 = null const {name2} = myObj2 // this will give error ...

1

Solved

I had an if statement in code which checks whether an object is defined and then check for equality for one of its properties. My if statement was like: if(obj && obj.a !== x) { // do somet...
Sumba asked 26/6, 2020 at 22:13

2

I have a TypeScript interface with some optional fields and a variable of that type: interface Foo { config?: { longFieldName?: string; } } declare let f: Foo; I'd like to put longFieldName ...
Shanitashank asked 14/11, 2019 at 21:6

© 2022 - 2025 — McMap. All rights reserved.