模块:插件

例如,当您想使用扩展另一个库的 JavaScript 代码时。

For example, when you want to work with JavaScript code which extends another library.

import { greeter } from "super-greeter";

// Normal Greeter API
greeter(2);
greeter("Hello world");

// Now we extend the object with a new function at runtime
import "hyper-super-greeter";
greeter.hyperGreet();

q9LKN2qDJ2E7yeTrPza5+QYVrhTxipy3QF/U4LBxyhANdmG/v7xnwKU/lq5RXEzk7qBP1g9hCke9Ko1n1k1w12WLzI2l4IkmVj8tDSu8hhFXWTsOtf3xtPuA3YQI+pfC

/*~ This example shows how to have multiple overloads for your function */
export interface GreeterFunction {
  (name: string): void
  (time: number): void
}

/*~ This example shows how to export a function specified by an interface */
export const greeter: GreeterFunction;

H35WIBP81WzcO8/D5ilqMEyZVNUxpureLzXkYx7vEYAXglRxsHV0AQX17mBJ6GaZwYdqJUTlOfnurKopSkJveeBniInH9V21ZpuZSdV43qY4+eMcK5SQB5f2at5wadaEBi5GNiiCEhkSX2mPGfzD0iUoCadwEIgEO9pfKBT9zYA=

// Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~]
// Project: [~THE PROJECT NAME~]
// Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]>

/*~ This is the module plugin template file. You should rename it to index.d.ts
 *~ and place it in a folder with the same name as the module.
 *~ For example, if you were writing a file for "super-greeter", this
 *~ file should be 'super-greeter/index.d.ts'
 */

/*~ On this line, import the module which this module adds to */
import { greeter } from "super-greeter";

/*~ Here, declare the same module as the one you imported above
 *~ then we expand the existing declaration of the greeter function
 */
export module "super-greeter" {
  export interface GreeterFunction {
    /** Greets even better! */
    hyperGreet(): void;
  }
}

xLh3iaxE81icjjmSfoEA/sFkJ6KEH21GeouAKNp+GehegQ6Q3iQdcTw57mRqNyrXxrDwliYeKMu16gDy1Msu28mFhhtMZtKA2lqRitMNZEhrxhr5UY5Tpynb4WrCT+Yio7A0vZ45KMhLRTMkBpC/uYZy9G4dvJG77evf86E9bGvqzqUYwK6GqEJMcR1tUWO45gcwDXEmeLaE+lGVQG/Jq2+eL3r4xEitcE9BJHEzM2U=