Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to first index of an Split and later make another Split, throws the error "Object is possibly 'undefined'" #48374

Closed
RodrigoTomeES opened this issue Mar 22, 2022 · 2 comments

Comments

@RodrigoTomeES
Copy link

Bug Report

Hi,

I am triying to get the extension file inside of an URL like:

🔎 Search Terms

Object is possibly 'undefined'
undefined

🕗 Version & Regression Information

  • I tried it in 4.5.4 version

⏯ Playground Link

Playground link with relevant code

💻 Code

export const getUrlExtension = (url: string): string =>
  url.split(/[#?]/)[0].split('.').pop().trim();

🙁 Actual behavior

Throw this error: Object is possibly 'undefined'.

🙂 Expected behavior

Doesn't throw any error, I think that never can be undefined.

@MartinJohns
Copy link
Contributor

MartinJohns commented Mar 22, 2022

Duplicate of #30406. You can use the non-null assertion operator for this case.

@RodrigoTomeES
Copy link
Author

@MartinJohns thanks! and sorry to duplicate the issue but I didn't find it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants