GithubHelp home page GithubHelp logo

zerthox / betterdiscord-types Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 2.0 61 KB

Type definitions for BetterDiscord.

Home Page: https://docs.betterdiscord.app/api/

License: MIT License

TypeScript 100.00%
betterdiscord typescript discord types typings

betterdiscord-types's Introduction

BetterDiscord Types

Typescript type definitions for BetterDiscord.

Usage

npm install @types/betterdiscord@github:zerthox/betterdiscord-types

Note: When installing under a name not starting with @types, definitions for globals may not be included. Importing the module somewhere or using for example typeRoots can fix this.

import type { Patcher, Filters } from "betterdiscord";

Custom Data Type

A custom type for BetterDiscord's BdApi.Data interface may be supplied. This enables more specific typing for Data's functions.

When used from BdApi directly, Data needs to be casted:

import type { Data } from "betterdiscord";

const TypedData = BdApi.Data as Data<CustomDataType>;

When using a bound version of BdApi, the custom type can be supplied in the constructor:

const BoundBdApi = new BdApi<CustomDataType>("PluginName");

betterdiscord-types's People

Contributors

duskt avatar thelazysquid avatar zerthox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

fmajestic duskt

betterdiscord-types's Issues

addStyle and removeStyle expect 1 argument less than they should

Hi, I'm having an issue with the DOM.addStyle and DOM.removeStyle methods, for some reason they expect 1 argument less than they should?

src/index.tsx:15:37 - error TS2554: Expected 1 arguments, but got 2.
15     this.bdApi.DOM.addStyle('test', `random css`);
                                       ~~~~~~~~~~~~

src/index.tsx:20:32 - error TS2554: Expected 0 arguments, but got 1.
20     this.bdApi.DOM.removeStyle('test');

className is not callable

This expression is not callable.
  Type '{ default: (...args: ArgumentArray) => string; }' has no call signatures. ts(2349)

utils.d.ts(1, 1): Type originates at this import.
A namespace-style import cannot be called or constructed,
and will cause a failure at runtime.
Consider using a default import or import require here instead.

The definition type is incorrect.

// use
import classNames from "classnames";
// instead of
import * as classNames from "classnames";

Allow supplying Data type

BdApi.Data is currently typed to be opaque to the user. The user could be allowed to optionally supply a type parameter to Data (and BdApi & BoundBdApi), which would be used to type accesses via save, load and delete.

Bug - Bound Patcher Loses Correct Typings

The Patcher methods on a bound instance of BdApi lose their proper typings, likely because the Bound type used to create the bound patcher doesn't retain the methods' generics.

With BdApi.Patcher.after:

image

With new BdApi("Caller").Patcher.after and the same arguments passed without the caller:

image

I've been playing around with trying to find some solutions, but the only thing that's worked so far is just redefining the patcher without the caller argument in its methods. There might be a more creative solution, but I haven't been able to find one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.