Add types for interpret

This commit is contained in:
Dimitri Benin 2018-12-04 23:52:20 +01:00
parent adda202607
commit 89f8981d79
4 changed files with 100 additions and 0 deletions

26
types/interpret/index.d.ts vendored Normal file
View File

@ -0,0 +1,26 @@
// Type definitions for interpret 1.1
// Project: https://github.com/tkellen/node-interpret
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export interface Hook {
(m: { extensions: string } | NodeModule): any;
install(m?: { extension: string; [key: string]: any }): void;
}
export type RegisterFn = (hook: Hook) => void;
export interface ExtensionDescriptor {
module: string;
register: RegisterFn;
}
export type Extension = string | ExtensionDescriptor | Array<string | ExtensionDescriptor>;
export interface Extensions {
[extension: string]: Extension | null;
}
export const extensions: Extensions;
export const jsVariants: Extensions;

View File

@ -0,0 +1,50 @@
import { extensions, jsVariants, Extensions } from 'interpret';
// $ExpectType Extensions
extensions;
// $ExpectType Extensions
jsVariants;
const myExts: Extensions = {
'.babel.js': [
{
module: 'babel-register',
register(hook) {
hook({ extensions: '.js' });
},
},
],
'.co': 'coco',
'.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
'.esm.js': {
module: 'esm',
register(hook) {
const esmLoader = hook(module);
require.extensions['.js'] = esmLoader('module')._extensions['.js'];
},
},
'.js': null,
'.jsx': [
{
module: 'node-jsx',
register(hook) {
hook.install({ extension: '.jsx', harmony: true });
},
},
],
'.toml': {
module: 'toml-require',
register(hook) {
hook.install();
},
},
'.ts': [
'typescript-require',
{
module: '@babel/register',
register(hook) {
hook({ extensions: '.ts' });
},
},
],
};

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"interpret-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }