Created
December 14, 2018 11:14
-
-
Save luvies/79aec3a56bd4b04de9b9cd00f05a9627 to your computer and use it in GitHub Desktop.
An example definition showing how to provide a definition file for a package without defining the entire thing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'shim-definitions' { // This module name should match the package name. | |
/** | |
* This allows something like VSCode to auto-import with the name | |
* `shimDefinitions`. It could be any other name you want. | |
*/ | |
const shimDefinitions: any; | |
/** | |
* Doing this allows you to import like so: | |
* ```ts | |
* import shimDefinitions from 'shim-definitions'; | |
* ``` | |
*/ | |
export default shimDefinitions; | |
/** | |
* To allow importing of specific declarations from the package, you can do something | |
* like this. | |
*/ | |
export const ExampleClass: any; | |
/** | |
* You can then import using | |
* ```ts | |
* import { ExampleClass } from 'shim-definitions'; | |
* ``` | |
* and use it normally. This would also allow you to build up the definition over time, | |
* so you could eventually turn it into: | |
* ```ts | |
* export class ExampleClass { | |
* exampleMethod(opts: object): string; | |
* } | |
* ``` | |
* This lets you type something you know and use, and leave other things out, saving time | |
* building the whole definition. | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment