0.1.1 • Published 8 months ago

trilium-types v0.1.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

trilium-types

A TypeScript @types package for Trilium Notes.

Installation

npm install @types/trilium@npm:trilium-types

Usage

Please note: These types were made for the latest version of Trilium (v0.61) which adds the attachments feature. If you're developing for the stable release (v0.60) you can still use these types, just avoid or ignore anything related to attachments.

TypeScript

The Trilium frontend api will automatically be available in all files since working with the frontend is the most common use-case. You can easily override this with the backend api if needed:

import {BackendAPI} from "trilium/backend";

declare const api: BackendAPI;

Otherwise, all the types should be available under trilium/frontend, trilium/backend, and trilium/common.

JavaScript

Similarly to in TypeScript, your IDE (like VSCode) should automatically pick up api as the frontend. You can override this using JSDoc syntax. First, make sure your IDE and/or linter are setup to allow an api global, then you can do.

/**
 * @type {import("trilium/backend").BackendAPI}
 */
const api = api;

For other types, you can follow the same methodology and use the JSDoc syntax with import.

Why?

Because it's nice to have autocompletion and type recognition whether you're using JS or TS.

Why not DefinitelyTyped?

I chose not to try to push this to DefinitelyTyped because I'm still an amateur when it comes to TypeScript and writing custom type definitions. They tend to have a quality requirement that I don't think I would meet.

Links

Check out my other Trilium-based projects:

Want more? Be sure to check out the Awesome Trilium list!