Change WidgetType.updateDOM from type to this #81

Merged
not-my-profile merged 1 commit from from-this into main 2026-03-12 08:16:25 +01:00
not-my-profile commented 2026-03-11 19:15:54 +01:00 (Migrated from github.com)

With this TypeScript understands that it's the same type as the subclass.

With `this` TypeScript understands that it's the same type as the subclass.
marijnh commented 2026-03-11 20:08:41 +01:00 (Migrated from github.com)

The this type means more than just "of the same class as this" in TypeScript, unfortunately. It asserts that the value is actually equal to this, and will cause weird type narrowing to happen. So unfortunately, though I agree it would be better to have a more precise type for this parameter, this isn't appropriate here.

The `this` type means more than just "of the same class as `this`" in TypeScript, unfortunately. It asserts that the value is actually equal to `this`, and will cause weird type narrowing to happen. So unfortunately, though I agree it would be better to have a more precise type for this parameter, `this` isn't appropriate here.
not-my-profile commented 2026-03-12 06:27:00 +01:00 (Migrated from github.com)

I'm not sure that's the case? Do you have an example for the "weird type narrowing" because I can't manage to reproduce it:

class Foo {
  prop: string = "";

  test(other: this) {
    if (this.prop == 'certain') {
      this.prop; // narrowed to 'certain'
      other.prop; // still string
    }
  }
}

TS Playground

I'm not sure that's the case? Do you have an example for the "weird type narrowing" because I can't manage to reproduce it: ```ts class Foo { prop: string = ""; test(other: this) { if (this.prop == 'certain') { this.prop; // narrowed to 'certain' other.prop; // still string } } } ``` [TS Playground](https://www.typescriptlang.org/play/?#code/MYGwhgzhAEBiD29oG8BQ1oAcBO9MC5oIAXbASwDsBzaAXmgCIGBuVdaYgUxIAp5iAFp2yFBZCAEoU7DGQBm0HmIgA6HHjr0A5MGHEwlLVLQZTHAeLW5MzaAHo70CmGy4A7pwAmHJDr0GKLRlTfiFsKzxbByJiMhAQGPJqYIBfdjSUoA)
marijnh commented 2026-03-12 08:16:09 +01:00 (Migrated from github.com)

It seems you are right. I distinctly remember giving up on this in the past because it misbehaved, but I cannot reproduce the problem in this case. The docs claim that it just dynamically takes the type of the current class, which seems safe. Let's try this then.

It seems you are right. I distinctly remember giving up on `this` in the past because it misbehaved, but I cannot reproduce the problem in this case. The [docs](https://www.typescriptlang.org/docs/handbook/2/classes.html#this-types) claim that it just dynamically takes the type of the current class, which seems safe. Let's try this then.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/view!81
No description provided.