[es6template] Add es6template types (#47959)

* Init

* Finish

* Do it like that

* Update types/es6template/index.d.ts

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
This commit is contained in:
Nathan Bierema 2020-09-24 16:47:42 -04:00 committed by GitHub
parent bbe6764e85
commit 52a1d17879
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,14 @@
import es6template = require('es6template');
// This rule is disabled because the library uses ES6-looking template strings, but with normal strings.
/* tslint:disable:no-invalid-template-strings */
const test1 = es6template('foo ${bar} baz ${quux}', {bar: 'BAR', quux: 'QUUX'});
const test2 = es6template.render('Hello ${place} and ${user.name}!', {
place: 'world',
user: {
name: 'Charlike'
}
});
const fn = es6template.compile('Hello ${place} and ${user.name}!');
const test3 = fn({place: 'world', user: {name: 'Charlike'}});

16
types/es6template/index.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
// Type definitions for es6template 1.0
// Project: https://github.com/zalmoxisus/es6-template
// Definitions by: Nathan Bierema <https://github.com/Methuselah96>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface Default {
render: (str: string, locals: Record<string, unknown>) => string;
// This rule is disabled because the caller of `compile()` knows what the type of the `locals` parameter should be when
// calling the `compile` function.
// tslint:disable-next-line:no-unnecessary-generics
compile: <Locals>(str: string) => ((locals: Locals) => string);
(str: string, locals: Record<string, unknown>): string;
}
declare const _default: Default;
export = _default;

View File

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

View File

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