Writing a declaration file: typescript

153 views Asked by At

How would I write a declaration file for

define(function() {
    'use strict';
    return Object.freeze({
        BTN_LINK: 'btnLink',
        COMBO_BOX: 'comboBox',
        TEXT: 'text'
    });
});
1

There are 1 answers

0
Fenton On BEST ANSWER

The type of the object you have frozen is:

type example = Readonly<{ BTN_LINK: string; COMBO_BOX: string; TEXT: string; }>;

You can get some guidance on best practices, and detailed instructions on writing type definitions if you want to find out more about ambient types. In particular, the best practices link describes how to create ghost modules, which you will be interested in if you want to put this type into a ghost module to describe the whole file.