diff --git a/tests/baselines/reference/symbolProperty61.js b/tests/baselines/reference/symbolProperty61.js new file mode 100644 index 0000000000000..e571eb4649293 --- /dev/null +++ b/tests/baselines/reference/symbolProperty61.js @@ -0,0 +1,65 @@ +//// [symbolProperty61.ts] +declare global { + interface SymbolConstructor { + readonly obs: symbol + } +} + +const observable: typeof Symbol.obs = Symbol.obs + +export class MyObservable { + constructor(private _val: T) {} + + subscribe(next: (val: T) => void) { + next(this._val) + } + + [observable]() { + return this + } +} + +type InteropObservable = { + [Symbol.obs]: () => { subscribe(next: (val: T) => void): void } +} + +function from(obs: InteropObservable) { + return obs[Symbol.obs]() +} + +from(new MyObservable(42)) + + +//// [symbolProperty61.js] +const observable = Symbol.obs; +export class MyObservable { + constructor(_val) { + this._val = _val; + } + subscribe(next) { + next(this._val); + } + [observable]() { + return this; + } +} +function from(obs) { + return obs[Symbol.obs](); +} +from(new MyObservable(42)); + + +//// [symbolProperty61.d.ts] +declare global { + interface SymbolConstructor { + readonly obs: symbol; + } +} +declare const observable: typeof Symbol.obs; +export declare class MyObservable { + private _val; + constructor(_val: T); + subscribe(next: (val: T) => void): void; + [observable](): this; +} +export {}; diff --git a/tests/baselines/reference/symbolProperty61.symbols b/tests/baselines/reference/symbolProperty61.symbols new file mode 100644 index 0000000000000..a4d45d7c1b9ee --- /dev/null +++ b/tests/baselines/reference/symbolProperty61.symbols @@ -0,0 +1,84 @@ +=== tests/cases/conformance/es6/Symbols/symbolProperty61.ts === +declare global { +>global : Symbol(global, Decl(symbolProperty61.ts, 0, 0)) + + interface SymbolConstructor { +>SymbolConstructor : Symbol(SymbolConstructor, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(symbolProperty61.ts, 0, 16)) + + readonly obs: symbol +>obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31)) + } +} + +const observable: typeof Symbol.obs = Symbol.obs +>observable : Symbol(observable, Decl(symbolProperty61.ts, 6, 5)) +>Symbol.obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31)) +>Symbol.obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31)) + +export class MyObservable { +>MyObservable : Symbol(MyObservable, Decl(symbolProperty61.ts, 6, 48)) +>T : Symbol(T, Decl(symbolProperty61.ts, 8, 26)) + + constructor(private _val: T) {} +>_val : Symbol(MyObservable._val, Decl(symbolProperty61.ts, 9, 16)) +>T : Symbol(T, Decl(symbolProperty61.ts, 8, 26)) + + subscribe(next: (val: T) => void) { +>subscribe : Symbol(MyObservable.subscribe, Decl(symbolProperty61.ts, 9, 35)) +>next : Symbol(next, Decl(symbolProperty61.ts, 11, 14)) +>val : Symbol(val, Decl(symbolProperty61.ts, 11, 21)) +>T : Symbol(T, Decl(symbolProperty61.ts, 8, 26)) + + next(this._val) +>next : Symbol(next, Decl(symbolProperty61.ts, 11, 14)) +>this._val : Symbol(MyObservable._val, Decl(symbolProperty61.ts, 9, 16)) +>this : Symbol(MyObservable, Decl(symbolProperty61.ts, 6, 48)) +>_val : Symbol(MyObservable._val, Decl(symbolProperty61.ts, 9, 16)) + } + + [observable]() { +>[observable] : Symbol(MyObservable[observable], Decl(symbolProperty61.ts, 13, 5)) +>observable : Symbol(observable, Decl(symbolProperty61.ts, 6, 5)) + + return this +>this : Symbol(MyObservable, Decl(symbolProperty61.ts, 6, 48)) + } +} + +type InteropObservable = { +>InteropObservable : Symbol(InteropObservable, Decl(symbolProperty61.ts, 18, 1)) +>T : Symbol(T, Decl(symbolProperty61.ts, 20, 23)) + + [Symbol.obs]: () => { subscribe(next: (val: T) => void): void } +>[Symbol.obs] : Symbol([Symbol.obs], Decl(symbolProperty61.ts, 20, 29)) +>Symbol.obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31)) +>subscribe : Symbol(subscribe, Decl(symbolProperty61.ts, 21, 25)) +>next : Symbol(next, Decl(symbolProperty61.ts, 21, 36)) +>val : Symbol(val, Decl(symbolProperty61.ts, 21, 43)) +>T : Symbol(T, Decl(symbolProperty61.ts, 20, 23)) +} + +function from(obs: InteropObservable) { +>from : Symbol(from, Decl(symbolProperty61.ts, 22, 1)) +>T : Symbol(T, Decl(symbolProperty61.ts, 24, 14)) +>obs : Symbol(obs, Decl(symbolProperty61.ts, 24, 17)) +>InteropObservable : Symbol(InteropObservable, Decl(symbolProperty61.ts, 18, 1)) +>T : Symbol(T, Decl(symbolProperty61.ts, 24, 14)) + + return obs[Symbol.obs]() +>obs : Symbol(obs, Decl(symbolProperty61.ts, 24, 17)) +>Symbol.obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>obs : Symbol(SymbolConstructor.obs, Decl(symbolProperty61.ts, 1, 31)) +} + +from(new MyObservable(42)) +>from : Symbol(from, Decl(symbolProperty61.ts, 22, 1)) +>MyObservable : Symbol(MyObservable, Decl(symbolProperty61.ts, 6, 48)) + diff --git a/tests/baselines/reference/symbolProperty61.types b/tests/baselines/reference/symbolProperty61.types new file mode 100644 index 0000000000000..f1b2f8c9c07a6 --- /dev/null +++ b/tests/baselines/reference/symbolProperty61.types @@ -0,0 +1,80 @@ +=== tests/cases/conformance/es6/Symbols/symbolProperty61.ts === +declare global { +>global : any + + interface SymbolConstructor { + readonly obs: symbol +>obs : unique symbol + } +} + +const observable: typeof Symbol.obs = Symbol.obs +>observable : unique symbol +>Symbol.obs : unique symbol +>Symbol : SymbolConstructor +>obs : unique symbol +>Symbol.obs : unique symbol +>Symbol : SymbolConstructor +>obs : unique symbol + +export class MyObservable { +>MyObservable : MyObservable + + constructor(private _val: T) {} +>_val : T + + subscribe(next: (val: T) => void) { +>subscribe : (next: (val: T) => void) => void +>next : (val: T) => void +>val : T + + next(this._val) +>next(this._val) : void +>next : (val: T) => void +>this._val : T +>this : this +>_val : T + } + + [observable]() { +>[observable] : () => this +>observable : unique symbol + + return this +>this : this + } +} + +type InteropObservable = { +>InteropObservable : InteropObservable + + [Symbol.obs]: () => { subscribe(next: (val: T) => void): void } +>[Symbol.obs] : () => { subscribe(next: (val: T) => void): void; } +>Symbol.obs : unique symbol +>Symbol : SymbolConstructor +>obs : unique symbol +>subscribe : (next: (val: T) => void) => void +>next : (val: T) => void +>val : T +} + +function from(obs: InteropObservable) { +>from : (obs: InteropObservable) => { subscribe(next: (val: T) => void): void; } +>obs : InteropObservable + + return obs[Symbol.obs]() +>obs[Symbol.obs]() : { subscribe(next: (val: T) => void): void; } +>obs[Symbol.obs] : () => { subscribe(next: (val: T) => void): void; } +>obs : InteropObservable +>Symbol.obs : unique symbol +>Symbol : SymbolConstructor +>obs : unique symbol +} + +from(new MyObservable(42)) +>from(new MyObservable(42)) : { subscribe(next: (val: number) => void): void; } +>from : (obs: InteropObservable) => { subscribe(next: (val: T) => void): void; } +>new MyObservable(42) : MyObservable +>MyObservable : typeof MyObservable +>42 : 42 + diff --git a/tests/cases/conformance/es6/Symbols/symbolProperty61.ts b/tests/cases/conformance/es6/Symbols/symbolProperty61.ts new file mode 100644 index 0000000000000..ff44c91714a21 --- /dev/null +++ b/tests/cases/conformance/es6/Symbols/symbolProperty61.ts @@ -0,0 +1,32 @@ +// @target: ES6 +// @declaration: true + +declare global { + interface SymbolConstructor { + readonly obs: symbol + } +} + +const observable: typeof Symbol.obs = Symbol.obs + +export class MyObservable { + constructor(private _val: T) {} + + subscribe(next: (val: T) => void) { + next(this._val) + } + + [observable]() { + return this + } +} + +type InteropObservable = { + [Symbol.obs]: () => { subscribe(next: (val: T) => void): void } +} + +function from(obs: InteropObservable) { + return obs[Symbol.obs]() +} + +from(new MyObservable(42))