Skip to content

Commit

Permalink
[ts] Hard-deprecate jQuery methods on $Window
Browse files Browse the repository at this point in the history
  • Loading branch information
1j01 committed Jun 19, 2024
1 parent 36897dc commit fb00f90
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ The API is unstable, and [Semantic Versioning](https://semver.org/spec/v2.0.0.ht
### Deprecated

- Accessing jQuery methods/properties on `$Window` instances is deprecated. Use the `element` property to access the underlying DOM element, and wrap it in a jQuery object if you wish to use jQuery methods.
- A deprecation notice will be logged each time a jQuery method or property is accessed on a `$Window` instance.
- A deprecation notice will be logged each time a jQuery method or property is accessed on a `$Window` instance, with a stack trace. In some cases, it will recommend a specific alternative.
- In TypeScript definitions, the jQuery methods and properties are mapped to `never`, with some common methods/properties given special deprecation notices.

### Changed

Expand Down
12 changes: 11 additions & 1 deletion os-gui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,17 @@ interface OSGUIWindow {
*
* This was a bad design decision.
*/
type OSGUI$Window = OSGUIWindow & $WindowDeprecatedJQueryPart;
type OSGUI$Window = OSGUIWindow & HardDeprecate<$WindowDeprecatedJQueryPart>;

// There doesn't seem to be any intrinsic in TypeScript to mark something as deprecated, it's JSDoc-only.
// This maps the properties of a type to `never`, making accessing them an error.
type HardDeprecate<T> = {
// JSDoc `@deprecated` doesn't seem to have an effect here, but interestingly,
// with this approach it does combine jQuery docs with deprecation notices that I add specifically,
// in the hover-over tooltip in VS Code.
// Without `HardDeprecate`, it shows fuller jQuery JSDocs, without my deprecation messages, only linking to where I use `@deprecated`.
[P in keyof T]: never;
};

interface $WindowDeprecatedJQueryPart extends JQuery<HTMLElement & { $window: OSGUI$Window }> {
/**
Expand Down

0 comments on commit fb00f90

Please sign in to comment.