[reserved-words] add type definitions for the reserved-words package (#33741)

* add reserved-words type definitions

* Review feedback: remove namespace, esModuleInterop and add KEYWORDS
This commit is contained in:
Spencer Miskoviak
2019-03-12 10:59:04 -07:00
committed by Wesley Wigham
parent 35fe3cad4b
commit de6ae2ea6f
4 changed files with 88 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
// Type definitions for reserved-words 0.1
// Project: https://github.com/zxqfox/reserved-words#readme
// Definitions by: Spencer Miskoviak <https://github.com/skovy>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
export type Dialect =
| "es3"
| 3
| "es5"
| 5
| "es2015"
| 6
| "es7"
| 7
| "es6"
| "next";
export interface Keywords {
[index: string]: {
[index: string]: true;
};
}
export const KEYWORDS: Keywords;
/**
* Checks a word for being a reserved word and returns true if the provided
* identifier string is a reserved word in some ECMAScript dialect.
*
* @param word word to check
* @param dialect dialect or version
* @param strict strict mode additionally checks whether word is a keyword or
* future reserved word under strict mode.
*/
export function check(
word: string,
dialect?: Dialect,
strict?: boolean
): boolean;
@@ -0,0 +1,24 @@
import { check, Dialect, KEYWORDS } from "reserved-words";
const dialect: Dialect = "es3";
// $ExpectType boolean
check("while");
// $ExpectType boolean
check("while", "es6");
// $ExpectType boolean
check("while", "es6", true);
// $ExpectType boolean
check("yield", 3);
// $ExpectError
check("yield", 1);
// $ExpectError
check("yield", "es4");
// $ExpectType true
KEYWORDS["6-strict"]["break"];
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strictFunctionTypes": true
},
"files": [
"index.d.ts",
"reserved-words-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }