This is a strawperson for the addition of multiple Regular Expression features popular in various languages and parsers. The primary influences for this proposal come from prior art in the following languages and regular expression engines:
A Range Type is a type that produces a new tuple or array type that derives from T
by dropping the excess ordered
elements of T
outside of the range starting at offset X
(inclusive) through offset Y
(exclusive).
A Range Type is denoted using a :
operator in what would otherwise be an Indexed Access Type:
type T = [1, 2, 3][0:2];
This proposal adds an Inverse Offset Type to the TypeScript type-space. An Inverse Offset Type is a type notation used to indicate that Type should be considered as an offset from the end of an Array Type or Tuple Type.
An Inverse Offset Type is denoted using a "hat" operator (^
) preceding a type:
type T = ^0;
Purpose:
- Primarily for developer tooling, such as for "rename" refactoring.
Syntax:
nameof IdentifierName
Examples:
Syntax:
// classes
class C {
#x = 1;
get x() => this.#x;
set x(value) => this.#x = value;
toString() => `C(${this.#x})`;
static create() => new C();
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Symbols: | |
// @@geti - An inverted-get. When present on an object used in an element access, calls this method rather than coercing | |
// the object to a String. | |
// ex: `a[b]` --> `b[@@geti](a)` | |
// @@seti - An inverted-set. When present on an object used in an element access assignment, calls this method rather | |
// than coercing the object to a String. | |
// ex: `a[b] = 1` --> `b[@@seti](a, 1)` | |
// @@indexedGet - Gets a value from an object in relation to a given `Index` instance. | |
// @@indexedSet - Sets a value on an object in relation to a given `Index` instance. | |
// @@slice - Gets values from an object in relation to a given `Interval` instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export {}; | |
/** A non-existent symbol used to define the types of events defined on an object */ | |
declare const kEvents: unique symbol; | |
/** Gets the events defined on an object. */ | |
type Events<T> = T extends { readonly [kEvents]: infer Events } ? Events : {}; | |
/** Get the names of events defined on an object. */ | |
type EventNames<T> = keyof Events<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Symbol.asyncDispose = Symbol.for("Symbol.asyncDispose"); | |
function __asyncUsing(obj) { | |
let state = obj !== null && obj !== undefined ? 0 : 2; | |
return { | |
[Symbol.asyncIterator]() { return this; }, | |
async next() { | |
if (state) return this.return(); | |
state = 1; | |
return { value: obj }; | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Lexical Grammar | |
// | |
SourceCharacter:: | |
> Any unicode code point | |
WhiteSpace:: | |
<TAB> | |
<VT> |