Commit 0dde9e25 authored by Nuno Martins's avatar Nuno Martins Committed by Christian Hergert

typescript.lang: missing keywords; add test file

- Adds missing keywords and basic type to the TS lang file.
- Adds TS utility types.
- Adds TS test file.
parent 502ee735
......@@ -36,23 +36,30 @@
<styles>
<style id="keyword" name="Keyword" map-to="def:keyword"/>
<style id="basic-type" name="Basic Data Type" map-to="def:type"/>
<style id="utility-type" name="Utility Type" map-to="def:function"/>
</styles>
<definitions>
<!-- TS specific stuff (i.e. stuff which is not JS) -->
<context id="ts-proper">
<include>
<!-- From: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words -->
<context id="keywords" style-ref="keyword">
<keyword>abstract</keyword>
<keyword>declare</keyword>
<keyword>enum</keyword>
<keyword>implements</keyword>
<keyword>infer</keyword>
<keyword>interface</keyword>
<keyword>is</keyword>
<keyword>keyof</keyword>
<keyword>module</keyword>
<keyword>namespace</keyword>
<keyword>package</keyword>
<keyword>private</keyword>
<keyword>protected</keyword>
<keyword>public</keyword>
<keyword>readonly</keyword>
<keyword>type</keyword>
</context>
......@@ -65,8 +72,25 @@
<keyword>number</keyword>
<keyword>object</keyword>
<keyword>string</keyword>
<keyword>symbol</keyword>
<keyword>unknown</keyword>
</context>
<!-- From: https://www.typescriptlang.org/docs/handbook/utility-types.html -->
<context id="utility-types" style-ref="utility-type">
<keyword>Exclude</keyword>
<keyword>Extract</keyword>
<keyword>InstanceType</keyword>
<keyword>NonNullable</keyword>
<keyword>Omit</keyword>
<keyword>Partial</keyword>
<keyword>Pick</keyword>
<keyword>Readonly</keyword>
<keyword>Record</keyword>
<keyword>Required</keyword>
<keyword>ReturnType</keyword>
<keyword>ThisType</keyword>
</context>
</include>
</context>
......
// Declarations
declare var v: any;
// Namespaces
namespace N {}
// Modules
declare module '*.txt' {
export const txt: string;
}
// Types
let num: number = 1;
let str: string = 'str';
let bool: boolean = true;
let obj: object = {};
let sym: symbol = Symbol();
let something: any;
let dunno: unknown;
let none: null = null;
let undef: undefined = undefined;
// Void type
function nothing(): void {
return;
}
// Never type
function err(): never {
throw new Error();
}
// Custom types
type T = Array<string | number>;
type Keys = keyof {a: number; b: number};
type Inferred<T> = T extends {a: infer U; b: infer U} ? U : never;
// Utility types
let part: Partial<{a: number; b: number}>;
let ro: Readonly<string[]>;
let rec: Record<string, any>;
let pick: Pick<{a: number; b: number}, 'a'>;
let omit: Omit<{a: number; b: number}, 'b'>;
let exc: Exclude<'a' | 'b' | 'c', 'a'>;
let ext: Extract<'a' | 'b' | 'c', 'a' | 'f'>;
let nonNull: NonNullable<string | null>;
let retT: ReturnType<() => string>;
let inst: InstanceType<typeof Number>;
let req: Required<{a?: number; b?: string}>;
let thisT: ThisType<any>;
// Interfaces
interface I {
prop: T;
}
interface II extends I {
readonly r: string;
}
// Classes
abstract class C implements II {
prop: T;
readonly r: string;
public pub: number;
protected prot: number;
private priv: number;
constructor(private priv2: string) {}
public abstract abst(): void;
}
// Enums
enum Dir {
Up = 1,
Down,
}
const enum E {
Yes = 1,
No = Yes - 1,
}
// Type guards
function isNumber(n: any): n is number {
return typeof n === 'number';
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment