UNPKG

1.44 kBPlain TextView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3/*-----------------------------------------------------------------------------
4| Copyright (c) 2014-2017, PhosphorJS Contributors
5|
6| Distributed under the terms of the BSD 3-Clause License.
7|
8| The full license is in the file LICENSE, distributed with this software.
9|----------------------------------------------------------------------------*/
10
11/**
12 * A runtime object which captures compile-time type information.
13 *
14 * #### Notes
15 * A token captures the compile-time type of an interface or class in
16 * an object which can be used at runtime in a type-safe fashion.
17 */
18export class Token<T> {
19 /**
20 * Construct a new token.
21 *
22 * @param name - A human readable name for the token.
23 * @param description - Token purpose description for documentation.
24 */
25 constructor(name: string, description?: string) {
26 this.name = name;
27 this.description = description ?? '';
28 this._tokenStructuralPropertyT = null!;
29 }
30
31 /**
32 * Token purpose description.
33 */
34 readonly description?: string; // FIXME remove `?` for the next major version
35
36 /**
37 * The human readable name for the token.
38 *
39 * #### Notes
40 * This can be useful for debugging and logging.
41 */
42 readonly name: string;
43
44 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
45 // @ts-ignore
46 private _tokenStructuralPropertyT: T;
47}