Skip to content

TS2551: Property XXX does not exist on type #61442

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

Closed
PatrykKuniczak opened this issue Mar 18, 2025 · 3 comments
Closed

TS2551: Property XXX does not exist on type #61442

PatrykKuniczak opened this issue Mar 18, 2025 · 3 comments

Comments

@PatrykKuniczak
Copy link

PatrykKuniczak commented Mar 18, 2025

🔎 Search Terms

"property does not exist", "property does not exist under if statement", "property not allowed after if statement excluding it"

🕗 Version & Regression Information

  • This changed between versions 5.0.0-beta and 5.9.0-dev.20250318
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about my problem

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250318#code/MYewdgzgLgBAsgeQCIFUAyBRA+gYQQOQDEBJAcRgF4YBvAKBhlDCgFNmAuG+hx8V5rBGAAnAJYAHKBE50ePALYBDKMAAWLaTADaAclVQo49gHpjAKnM6ANDD0Hx00xbPXbAHkUAbT1gCuwzwgAPh0AXStuOQArTS0AAyZ+KGNRMAATFgAPADpRUQAzFmyYuPDImABfCIYq2gqYRQheSCgAblpaJmgYJAxCAEF0ABVcAAkEYhwMAGVKbW5qGDBFeRZOHRw+NlhpkQlYAAoMTJZgX1YYAClZ8BgAdRYAIxgABUUAcxYASlcANy9fGtbIltjpKtUaEsVkCNltmDBdmJJDAAEq+ZiiVYwA7EMBRU6wa4wW7TcSnAqiYAwfrAKCicBNTyiADWLFeIHEvnEMBwTOAzJ+Nn+nkB6xBzAAtMJ0XTVmDaqEGk0um0OllxCBhLAoABPMnwEBpXyeFj4aFDPVsqgHXVkkD5Hp9QZoEY4caTGZfLRgXzyR4sYShXTCwFhdq0dWa2AqmBZFbiE1zRo6sBUg7ceSG42m6GcOBZk1m1YWskRL6UIJcBgFbGZo2F6HZaCKLUQO6iKCqA46cVQHRfcuyHg1g517NFq0UKg9uFQKUyzEsftVuQwUwwUYYFEYHSzIabmAYfBIGAIQgwfcYGBoYgANSvZ+Bs-nGLlNgAQighhfZkgEDN8B0IZtzwUh8GIAAtK9iG-Yh8EPNBpivaYhn6IYMDgI8hnKBhhBYKB-DAdo5Aqbh6hYQI2SHBh10-b9L23XdqXgrcUQQFFyi6EATWyTwQHeA5EFQTBcAIEhSC0McG1WUIvg6OR12IGB8AwDATyGBBXjQfophgGDygKUcCxzLEAEIpyfZhthfWUly+ajVy4ni+IEoT0GwPAiDISTjInWTylIhTjFPDigpgAABKQJXVAlouEYRNRwngnKKFzBOQdzRK8iSpJMlh-JqeTmggbjUv4g44iQCj8JYNJOAAEmoXKJwqOIvnaCpwzjeQExYbtexsxd+1aIA

💻 Code

Code is very, very simple, let's look on playground

🙁 Actual behavior

TS2551: Property content-runtime does not exist on type

🙂 Expected behavior

Not occur, because of part TS complaining about, not exists on else statement at all.

@nmain
Copy link

nmain commented Mar 18, 2025

startsWith doesn't participate in narrowing out of the box. If you want this, you can add it yourself:

declare global {
  interface String {
    startsWith<K extends string>(searchString: K): this is `${K}${string}`
  }
}

This will fix your example.

@PatrykKuniczak
Copy link
Author

startsWith doesn't participate in narrowing out of the box. If you want this, you can add it yourself:

declare global {
interface String {
startsWith(searchString: K): this is ${K}${string}
}
}
This will fix your example.

Thanks, but it looks like overkill, for my problem, i mean that should work with native solution.

Why it doesn't work and have you plan to implement solution for this?

@nmain
Copy link

nmain commented Mar 18, 2025

Ahh, I found the original. Duplicate of #46958; search terms startsWith in:title.

have you plan to implement solution for this?

See #46958 (comment)

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