Skip to content

Typescript: simple demo with custom declaration file, included with reference path

Notifications You must be signed in to change notification settings

deeper-x/custom-declaration

Repository files navigation

Typescript - Declaration file for a custom module

With this simple example, we show how to define and set up a type definition for a custom Javascript library, in a Typescript module.

We write and publish on npm a test module, a "reverse with sharps" library: given an input string, it returns the reversed version with some sharps around.

Example:

console.log(reverseWithSharps("ALBERTO"));

// result: ## OTREBLA ##

Then we use it in a TS file, simply defining a declaration file, requiring an input string as a parameter, returning a string as a result:

/// <reference path="./reverse-with-sharps.d.ts"/>
import * as myModule from 'reverse-with-sharps';

console.log(myModule.reverseWithSharps("ALBERTO"));

// result: ## OTREBLA ##

About

Typescript: simple demo with custom declaration file, included with reference path

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published