#A question about `.d.ts`

25 messages · Page 1 of 1 (latest)

mental meteor
#

Hello everyone, I am currently making a pull request for the DesModder, which currently uses a package on npm called @types/desmos which features types and interfaces for the Desmos API. The entire package is a singular .d.ts file with a giant namespace in it. The package however, also features some functions that can be called, but the .d.ts file only contains a declaration for those functions, but not the definitions. How can I be able to call them? Where does their definition come from?

#

Example

/**
     * Creates a four function calculator object to control the calculator embedded in the DOM element specified by element.
     */
    function FourFunctionCalculator(
        element: HTMLElement,
        options?: {
            /**
             * Allow external hyperlinks (e.g. to braille examples)
             * @default true
             */
            links?: boolean;
            /**
             * Picks the extra function(s) that appear in the top bar. Maximum 2, minimum 1.
             * @default ["sqrt"]
             */
            additionalFunctions?:
                | ("exponent" | "percent" | "fraction" | "sqrt")
                | ReadonlyArray<"exponent" | "percent" | "fraction" | "sqrt">;
            /**
             * Base font size.
             * @default 16
             */
            fontSize?: number;
            /**
             * Display the calculator with an inverted color scheme.
             * @default false
             */
            invertedColors?: boolean;
            /**
             * Display the settings menu.
             * @default true
             */
            settingsMenu?: boolean;
            /**
             * Language. See the Languages section for more information.
             * @default "en"
             */
            language?: string;
            /**
             * Set the input and output Braille code for persons using refreshable Braille displays.
             * @default "none"
             */
            brailleMode?: "nemeth" | "ueb" | "none";
            /**
             * Allow users to write six-dot Braille characters using the Home Row keys (S, D, F, J, K, and L). Requires that brailleMode be 'nemeth' or 'ueb'.
             * @default false
             */
            sixKeyInput?: boolean;
            /**
             * Display the calculator in a larger font.
             * @default false
             */
            projectorMode?: boolean;
            /**
             * When true, users are able to toggle between decimal and fraction output in evaluations if Desmos detects a good rational approximation.
             * @default false
             */
            decimalToFraction?: boolean;
            /**
             * Limit the size of an expression to 100 characters.
             * @default false
             */
            capExpressionSize?: boolean;
        },
    ): BasicCalculator;

The comment says it creates a BasicCalculator, but where is the function body?

wicked ermine
mental meteor
#

There is no .js file in that package

wicked ermine
#

@types/desmos only provides types

mental meteor
wicked ermine
#

it provides types from the desmos package

#

that's what @types packages are for

#

the impl is in desmos

mental meteor
#

Oh

wicked ermine
#

@types is under DefinitelyTyped, as noted in the README

mental meteor
#

Alright then

#

so this applies to all packages in @types

wicked ermine
#

yes

#

well, not all, actually.

mental meteor
#

understood

#

oh

wicked ermine
#

some @types packages were created before the original package came with types. in some cases, the original package started publishing their own types, and the @types package was left as a stub

#

so sometimes you might see @types packages that are out-of-date or empty, just because they've been superceded

#

but the original intent is the same, just providing types for packages that don't have them

mental meteor
#

alright

#

thanks

#

!closed