While learning TypeScript -- an ongoing process -- I sometimes struggle to find the canonical docs in the Handbook. So today, I asked grok to generate a list of TypeScript and JavaScript keywords and links to their docs.
Thank you all MDN and TypeScript contributors. 🙏
Keyword | Description | Docs |
---|---|---|
any |
Represents any type, bypassing type checking | any |
as |
Performs type assertion or const assertion | type assertions |
asserts |
Used in type predicates to assert a condition | assertion functions |
bigint |
Represents large integers | bigint |
boolean |
Represents true or false values | boolean |
declare |
Specifies ambient declarations | ambient declarations |
enum |
Defines a set of named constants | enums |
extends |
Extending types. cf JavaScript extends | extends interface |
infer |
Infers a type variable in conditional types | infer types |
is |
Used in type predicates | type predicates |
keyof |
Creates a type from an object’s keys | keyof types |
module |
Declares a module (similar to namespace) | modules |
namespace |
Organizes code in a named scope | namespaces |
never |
Represents values that never occur | never |
number |
Represents numeric values | number |
object |
Represents non-primitive types | object |
out |
Specifies variance in generic types | variance annotations |
override |
Ensures a method overrides a base class method | override |
readonly |
Prevents reassignment of properties | readonly |
satisfies |
Ensures a value matches a type without casting | satisfies operator |
string |
Represents string values | string |
symbol |
Represents unique identifiers | symbol |
type |
Defines a type alias | type aliases |
undefined |
Represents an undefined value | undefined |
unique |
Used with symbols for unique types | unique symbol |
unknown |
Represents values of unknown type | unknown |
Keyword | Description | Docs |
---|---|---|
async |
Declares an asynchronous function | async function |
await |
Pauses async function until a promise resolves | await |
break |
Exits a loop or switch statement | break |
case |
Defines a case in a switch statement | switch |
catch |
Handles exceptions in a try-catch block | try...catch |
class |
Declares a class | class |
const |
Declares a block-scoped, read-only variable | const |
continue |
Skips to the next iteration of a loop | continue |
debugger |
Invokes a debugging breakpoint | debugger |
default |
Specifies the default case in a switch or export | switch |
delete |
Deletes a property from an object | delete |
do |
Starts a do-while loop | do...while |
else |
Specifies alternative execution in an if statement | if...else |
export |
Exports a module member | export |
extends |
Indicates inheritance in classes | extends |
false |
Boolean literal for false | Boolean |
finally |
Executes after a try-catch block | try...catch |
for |
Creates a loop (for, for...of, for...in) | for |
function |
Declares a function | function |
get |
Defines a getter method | get |
if |
Conditional statement | if...else |
implements |
Reserved in JavaScript; specifies interface implementation in TypeScript | implements |
import |
Imports module members | import |
in |
Checks if a property exists in an object | in |
instanceof |
Tests if an object is an instance of a constructor | instanceof |
interface |
Reserved in JavaScript; defines type contracts in TypeScript | interface |
let |
Declares a block-scoped variable | let |
new |
Creates an instance of a constructor | new |
null |
Represents the absence of a value | null |
package |
Reserved in JavaScript; not used in TypeScript | strict mode |
private |
Reserved in JavaScript; restricts access in TypeScript | private |
protected |
Reserved in JavaScript; allows subclass access in TypeScript | protected |
public |
Reserved in JavaScript; allows unrestricted access in TypeScript | public |
return |
Exits a function and returns a value | return |
set |
Defines a setter method | set |
static |
Defines static class members | static |
super |
Refers to the parent class | super |
switch |
Evaluates an expression against multiple cases | switch |
this |
Refers to the current object context | this |
throw |
Throws an exception | throw |
true |
Boolean literal for true | Boolean |
try |
Attempts execution that may throw an error | try...catch |
typeof |
Returns the type of a value | typeof |
var |
Declares a variable (function or global scope) | var |
void |
Evaluates an expression without returning a value | void |
while |
Creates a while loop | while |
with |
Extends the scope chain (deprecated) | with |
yield |
Pauses and returns a value from a generator | yield |