Microsoft/TypeScript
Ver no GitHubabstract type guard does not narrow when keyed with a unique symbol
Open
#62.247 aberto em 10 de ago. de 2025
BugDomain: check: Control FlowHelp Wanted
Métricas do repositório
- Stars
- (48.455 stars)
- Métricas de merge de PR
- (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)
Description
🔎 Search Terms
abstract type guard symbol
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about abstract type guard
⏯ Playground Link
💻 Code
const isBar = Symbol("isBar");
abstract class Foo {
abstract isBar(): this is Bar;
abstract [isBar](): this is Bar;
method(): void {
if (this[isBar]()) {
// This should not be an error, it should work the same as .isBar()
this.barMethod();
} else if (this.isBar()) {
this.barMethod();
}
}
}
class Bar extends Foo {
override isBar(): this is Bar {
return true;
}
override [isBar](): this is Bar {
return true;
}
barMethod(): void {}
}
🙁 Actual behavior
TS reports an error:
Property 'barMethod' does not exist on type 'Foo'. Did you mean 'method'?(2551)
🙂 Expected behavior
No error should happen here, the type guard should work the same as the non-symbol version of the method.
Additional information about the issue
No response