ImprovedHighlight of Weekly #003

Typed `this` inside JS patches

patch() extensions now type `this` as the patched object, so editors complete and type-check the target's members. `super` stays untyped.

Versions20.0
ModulesWeb web
AppFramework & technical

Pull requests and commits

BranchPull requestCommit
20.0odoo/odoo#289631 ↗a9e3b70327 ↗

Commit message

[IMP] web: type `this` inside patch extensions

Annotate the `extension` parameter with `ThisType<T & U>` so that `this`
inside a patch resolves to the patched object (target plus extension)
rather than to the extension literal alone. Patch authors then get
completion and type checking on the target's members.

`super` cannot be covered the same way: TypeScript always resolves
`super` in an object literal method to `any`, whatever the contextual
type, so no annotation can reach it. Typing it would mean passing the
original as a named value, i.e. changing the `patch` API and every call
site, which is not worth it here.

My stack

Pick the versions and apps you run. Weekly digests, this week's table and All changes then show only what concerns you. Saved in this browser.

Versions
Apps
Modules