Microsoft/TypeScript
Auf GitHub ansehenabstract type guard does not narrow when keyed with a unique symbol
Open
#62.247 geöffnet am 10. Aug. 2025
BugDomain: check: Control FlowHelp Wanted
Repository-Metriken
- Stars
- (48.455 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)
Beschreibung
🔎 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