mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
[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:
committed by
Wesley Wigham
parent
35fe3cad4b
commit
de6ae2ea6f
Vendored
+40
@@ -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"];
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user