-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Domain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
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}`.
benlesh
Metadata
Metadata
Assignees
Labels
Domain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsFixedA PR has been merged for this issueA PR has been merged for this issue