obsidian-typings 5.23.0 → 5.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +195 -15
  2. package/package.json +23 -13
package/README.md CHANGED
@@ -1,26 +1,206 @@
1
- # obsidian-typings
1
+ # Obsidian Typings
2
2
 
3
- TypeScript type definitions for Obsidian's internal/unofficial APIs.
3
+ [![NPM downloads](https://img.shields.io/npm/v/obsidian-typings?color=red&label=Version%3A&logo=npm&logoColor=white&labelColor=red)](https://www.npmjs.com/package/obsidian-typings)
4
+ [![NPM downloads](https://img.shields.io/npm/dw/obsidian-typings?style=flat&label=Downloads)](https://www.npmjs.com/package/obsidian-typings)
5
+ [![GitHub Repo stars](https://img.shields.io/github/stars/obsidian-typings/obsidian-typings?color=yellow&label=Stargazers%3A&logo=OpenTelemetry&logoColor=yellow)](https://github.com/obsidian-typings/obsidian-typings/stargazers)
4
6
 
5
- This package is an alias for [`@obsidian-typings/obsidian-public-latest`](https://www.npmjs.com/package/@obsidian-typings/obsidian-public-latest), which always points to the latest public Obsidian release typings.
7
+ **Obsidian Typings** provides **TypeScript definitions** for Obsidian’s **undocumented and internal APIs**.
6
8
 
7
- ## Installation
9
+ It extends the official [Obsidian API](https://github.com/obsidianmd/obsidian-api/) with:
8
10
 
9
- ```bash
10
- npm install obsidian-typings
11
+ - Additional type definitions for internal methods, properties, and plugins.
12
+ - Explanations and usage examples to make undocumented parts easier to understand.
13
+ - Helper utilities and interfaces for working with Obsidian’s internals in a safer, type-safe way.
14
+
15
+ This package is designed for plugin developers who want to access Obsidian's internal APIs in a type-safe manner,
16
+ while also keeping their code maintainable and less reliant on `@ts-ignore`/`@ts-expect-error`.
17
+
18
+ > [!IMPORTANT]
19
+ >
20
+ > - This package is **not affiliated with, or endorsed by, the Obsidian team**.
21
+ > - It does **not** cover every aspect of the Obsidian API.
22
+ > - Typings are based on reverse engineering and may be **inaccurate or unstable**. They can change without notice in future releases.
23
+ > - Always **test thoroughly** and **add fallbacks** when using internal APIs.
24
+
25
+ ## Versioning and Release Channels
26
+
27
+ [Obsidian](https://obsidian.md) has two main release channels:
28
+
29
+ - `public` - stable versions available to all users.
30
+ - [`catalyst`](https://help.obsidian.md/catalyst) (`beta`, `early access`) - versions only available to users with a catalyst license, has early access to new features.
31
+
32
+ If you use internal APIs, you may need to support users on both channels.
33
+ The availability or behavior of some APIs can differ between versions, which may lead to bugs or errors if these changes are not accounted for in your plugin.
34
+
35
+ To make it easier to adapt to these differences, this package provides typings for both channels.
36
+
37
+ Typings for each `Obsidian` version can be found in their own git branches: namely `release/obsidian-public/*` and `release/obsidian-catalyst/*`:
38
+
39
+ - Latest `public` release: [`release/obsidian-public/1.12.7`](https://github.com/obsidian-typings/obsidian-typings/tree/release/obsidian-public/1.12.7) | [`@obsidian-typings/obsidian-public-1.12.7`](https://www.npmjs.com/package/@obsidian-typings/obsidian-public-1.12.7)
40
+ - Latest `catalyst` release: [`release/obsidian-catalyst/1.12.6`](https://github.com/obsidian-typings/obsidian-typings/tree/release/obsidian-catalyst/1.12.6) | [`@obsidian-typings/obsidian-catalyst-1.12.6`](https://www.npmjs.com/package/@obsidian-typings/obsidian-catalyst-1.12.6)
41
+
42
+ Older versions of the package are available, but support for them is limited.
43
+ In most cases, we recommend to always use the latest release.
44
+
45
+ ## Set-up
46
+
47
+ ### 1. Install via `npm`
48
+
49
+ - Latest `public` release (recommended):
50
+ - `npm install --save-dev @obsidian-typings/obsidian-public-latest`
51
+ - Latest `catalyst` (`beta`) release:
52
+ - `npm install --save-dev @obsidian-typings/obsidian-catalyst-latest`
53
+ - Specific Obsidian version (should match `minAppVersion` in your plugin's `manifest.json`):
54
+ - `npm install --save-dev @obsidian-typings/obsidian-public-1.12.7`
55
+ - `npm install --save-dev @obsidian-typings/obsidian-catalyst-1.12.6`
56
+ - Legacy package name (alias for `@obsidian-typings/obsidian-public-latest`):
57
+ - `npm install --save-dev obsidian-typings`
58
+
59
+ <!-- markdownlint-disable MD033 -->
60
+
61
+ ### 2. Enable in `tsconfig.json` (recommended) <span id="add-types-setting-to-tsconfig-json"></span>
62
+
63
+ <!-- markdownlint-enable MD033 -->
64
+
65
+ Add the package to the `types` array of your `tsconfig.json` to make all extended typings available globally without explicit importing them:
66
+
67
+ ```json
68
+ {
69
+ "compilerOptions": {
70
+ "...": "...",
71
+ "types": [
72
+ "@obsidian-typings/obsidian-public-latest"
73
+ ]
74
+ }
75
+ }
11
76
  ```
12
77
 
13
- ## Migration
78
+ > [!WARNING]
79
+ >
80
+ > If other `@types/*` packages stop being recognized after adding the typings to the `types`, you may need to re-add them to the `types` list.
81
+ >
82
+ > ```json
83
+ > {
84
+ > "compilerOptions": {
85
+ > "...": "...",
86
+ > "types": [
87
+ > "@obsidian-typings/obsidian-public-latest",
88
+ > "some-package-name"
89
+ > ]
90
+ > }
91
+ > }
92
+
93
+ ### 3. Importing explicitly (alternative)
94
+
95
+ Instead of adding the package to your `types`, you can also import it directly:
96
+
97
+ ```ts
98
+ import type {} from '@obsidian-typings/obsidian-public-latest';
99
+ ```
100
+
101
+ ## Usage
102
+
103
+ ### `obsidian` module internals
104
+
105
+ To access types from the `obsidian` module, the import syntax does not change:
106
+
107
+ ```ts
108
+ import type { App } from 'obsidian';
109
+
110
+ function printInternalPlugins(app: App): void {
111
+ console.log(app.internalPlugins);
112
+ }
113
+ ```
14
114
 
15
- This package now re-exports from the `@obsidian-typings` org. For more control, install a specific version directly:
115
+ ### Additional interfaces
16
116
 
17
- ```bash
18
- # Always latest public
19
- npm install @obsidian-typings/obsidian-public-latest
117
+ Additional interfaces added by this package (which do not exist in the official API), can be imported as:
20
118
 
21
- # Specific Obsidian version
22
- npm install @obsidian-typings/obsidian-public-1.12.7
119
+ ```ts
120
+ import type { InternalPlugins } from '@obsidian-typings/obsidian-public-latest';
23
121
 
24
- # Catalyst (early access)
25
- npm install @obsidian-typings/obsidian-catalyst-latest
122
+ function getInternalPlugins(app: App): InternalPlugins {
123
+ return app.internalPlugins;
124
+ }
26
125
  ```
126
+
127
+ ### Implementations
128
+
129
+ Additional helper functions/types/... added by this package can be used by importing from the `/implementations` subpath:
130
+
131
+ ```ts
132
+ import { InternalPluginName } from '@obsidian-typings/obsidian-public-latest/implementations';
133
+
134
+ // If you forget the `/implementations` part:
135
+ // import { InternalPluginName } from '@obsidian-typings/obsidian-public-latest';
136
+ // You will not be able to use the runtime values and the code below will not compile.
137
+
138
+ this.app.internalPlugins.getEnabledPluginById(InternalPluginName.FileExplorer);
139
+ ```
140
+
141
+ The list of all available implementations can be found in the `src/obsidian/implementations` folder in the corresponding release branch ([example for `1.9.10 public`](https://github.com/obsidian-typings/obsidian-typings/tree/release/obsidian-public/1.9.10/src/obsidian/implementations)).
142
+
143
+ ### Extend with your own typings
144
+
145
+ If you need to extend the typings provided by this package, add the following to any `.d.ts` file in your project:
146
+
147
+ ```ts
148
+ export {}; // This line is required. If there are no top-level `import/export` statements, your typings will work not as expected.
149
+ declare module '@obsidian-typings/obsidian-public-latest' {
150
+ interface PluginsPluginsRecord {
151
+ ['my-plugin-id']: MyPlugin;
152
+ }
153
+ }
154
+ ```
155
+
156
+ ## Disclaimer
157
+
158
+ > [!WARNING]
159
+ >
160
+ > Make sure to read below section in detail before using these typings.
161
+ >
162
+ > Use at your own risk, verify that the code behaves as expected, and be prepared to update your code if the API changes.
163
+
164
+ Please be aware that there is a good reason why (some of) the functions and types defined here are not included with the official API definitions:
165
+
166
+ - The methods are not fully defined, and will be changed or removed in the near-future
167
+ - There is a high risk of the code behaving unexpectedly if used improperly
168
+ - The function was never meant to be used
169
+
170
+ Please use the functions and variables provided by this package with caution.
171
+ Be prepared to update your code if the API changes, and only use the functions if you are confident that you understand what they will do.
172
+ Reference the [official API](https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts) first to see if your problem may be solved with a documented function, or search in the `#plugin-dev` channel of the Obsidian Discord server.
173
+ Some functions will also contain `@remark` TSDoc tags that provide alternatives or better solutions.
174
+
175
+ Furthermore, there is a very high chance that there are mistakes in the typings, despite best efforts.
176
+ All types had to be deduced from context, manually running the function, or from the minified app code.
177
+ Always verify that your code behaves as expected, both in terms of types and runtime behavior.
178
+
179
+ > [!WARNING]
180
+ >
181
+ > While the typings themselves were hand-written by the package maintainers and contributors, the majority of the `@tsdoc` documentation has been minimally completed using generative AI and may be inaccurate.
182
+
183
+ &nbsp;
184
+
185
+ > [!TIP]
186
+ >
187
+ > If you find any issues with the typings or documentation, please feel free to [open an issue](https://github.com/obsidian-typings/obsidian-typings/issues) or submit a pull request.
188
+
189
+ With these scary disclaimers out of the way, hopefully these typings will help you in removing 90% of the `@ts-ignore`/`@ts-expect-error` you have in your codebase, or discover solutions that didn't seem possible before.
190
+
191
+ ## Tags
192
+
193
+ - `@remark` warnings, caveats, or suggested alternatives.
194
+ - `@tutorial` extra guidance and examples.
195
+ - `@official` comes from the [official API](https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts).
196
+ - `@unofficial` based on reverse engineering.
197
+
198
+ ## Migration
199
+
200
+ If you were using a `1.x.x` version of this package, see the [Migration guide](https://github.com/obsidian-typings/obsidian-typings/blob/main/MIGRATION.md) for upgrading to `2.0.0` or newer.
201
+
202
+ ## Contributing
203
+
204
+ Feel free to start typing any part of the Obsidian API that is not yet typed, or fixing/adding additional descriptions to existing typings. If you are unsure about anything, don't hesitate to open an issue.
205
+
206
+ A brief tutorial is available on how you can get started with adding new typings, or fixing existing ones, see: [CONTRIBUTING.md](https://github.com/obsidian-typings/obsidian-typings/blob/main/CONTRIBUTING.md).
package/package.json CHANGED
@@ -1,22 +1,32 @@
1
1
  {
2
- "name": "obsidian-typings",
3
- "version": "5.23.0",
2
+ "dependencies": {
3
+ "@obsidian-typings/obsidian-public-latest": "^5.24.0"
4
+ },
4
5
  "description": "TypeScript type definitions for Obsidian's internal/unofficial APIs. Wrapper for @obsidian-typings/obsidian-public-latest.",
5
- "type": "module",
6
- "main": "",
7
- "types": "./types.d.cts",
8
6
  "exports": {
9
7
  ".": {
10
- "require": { "types": "./types.d.cts" },
11
- "import": { "types": "./types.d.mts" }
8
+ "import": {
9
+ "types": "./types.d.mts"
10
+ },
11
+ "require": {
12
+ "types": "./types.d.cts"
13
+ }
12
14
  },
13
15
  "./implementations": {
14
- "require": { "types": "./implementations.d.cts", "default": "./implementations.cjs" },
15
- "import": { "types": "./implementations.d.mts", "default": "./implementations.mjs" }
16
+ "import": {
17
+ "default": "./implementations.mjs",
18
+ "types": "./implementations.d.mts"
19
+ },
20
+ "require": {
21
+ "default": "./implementations.cjs",
22
+ "types": "./implementations.d.cts"
23
+ }
16
24
  }
17
25
  },
18
- "dependencies": {
19
- "@obsidian-typings/obsidian-public-latest": "^5.22.2"
20
- },
21
- "license": "MIT"
26
+ "license": "MIT",
27
+ "main": "",
28
+ "name": "obsidian-typings",
29
+ "type": "module",
30
+ "types": "./types.d.cts",
31
+ "version": "5.24.0"
22
32
  }