question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object is possibly 'undefined'

See original GitHub issue

Hi!

I’m using TypeScript 3.0.3 and while using your plugins it’s pretty annoying because I need to wrap them inside “if/else” statements to avoid this error; Object is possibly 'undefined'

Here an example of my code:

import { Plugins, StatusBarStyle } from '@capacitor/core';

const { StatusBar } = Plugins;

StatusBar.setStyle({
  style: StatusBarStyle.Dark
});

Note: the error is for the StatusBar.setStyle

How do you manage that? Seems really repetitive to write if/else each time I need to use these plugins 😢

Thank you,

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jcesarmobilecommented, May 21, 2019

Thanks @simonhaenisch! closing

0reactions
simonhaenischcommented, May 21, 2019

This has been fixed by #1507.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I solve the error 'TS2532: Object is possibly ...
Typescript is saying that change or data is possibly undefined (depending on what onUpdate returns). So you should wrap it in a null/undefined...
Read more >
Object is possibly 'undefined' error in TypeScript | bobbyhadz
The "Object is possibly 'undefined'" error occurs when we try to access a property on an object that may be undefined (e.g. marked...
Read more >
[Solved] Object is possibly 'undefined' error in TypeScript
The Object is possibly 'undefined' occurs when we try to access a property of an object that is undefined . Sometimes few properties...
Read more >
How to solve 'Object is possibly undefined' error in TypeScript?
Let's understand why the error occurs. The reason for the error is, that while declaring the employee1 object, we are passing only the...
Read more >
How to solve TypeScript possibly undefined value
This article goes over 5 methods to solve a problem like TS2532: Object is possibly 'undefined'. You can use IF conditions, logical operator ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found