Closed
Description
Found talking to @benlesh
If you try to write the following
interface SymbolConstructor {
observable: symbol;
}
declare function from<T>(obj: { [typeof Symbol.observable](): Observable<T> }): Observable<T>;
// ^^^^^^ Look at this use of 'typeof'.
type Observer<T> = (x: T) => void;
interface Observable<T> {
subscribe(observer: Observer<T>): { unsubscribe(): void }
}
You'll get an error like
A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.
This is pretty confusing, because we do support well-known symbols that are declared with symbol
instead of unique symbol if you use the following syntax:
declare function from<T>(obj: { [Symbol.observable](): Observable<T> }): Observable<T>;
// ^ No 'typeof'.
It would be great if we could detect this case and specialize the error message with something like
Computed property names can only be named with well-known symbols without the 'typeof' operator. Try replacing `typeof {0}` with `{0}`.