-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
🔎 Search Terms
extends Symbol
extends Symbol index key
extending Symbol
InjectionKey
cannot be used as an index type
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries
- I was unable to test this on versions prior to 4.4(PR Index signatures for symbols and template literal strings #44512) because symbols weren't accepted as index types
⏯ Playground Link
Playground link with relevant code
💻 Code
// Reference for InjectionKey: https://github.com/vuejs/vue-next/blob/2d4f4554349db6b07027d0c626f56c48d0233f67/packages/runtime-core/src/apiInject.ts#L6
interface InjectionKey<T> extends Symbol {}
interface SomeInterface { foo: string }
const key: InjectionKey<SomeInterface> = Symbol()
const records: Record<string | symbol, any> = {};
records['a-string']; // Works
records[Symbol()]; // Works
records[key]; // Doesn't work
records[key as symbol]; // Works
// Assignability tests
const _key1: symbol = key; // Doesn't work
const _key2: symbol = key as symbol; // Works
// Casting tests
key as symbol; // Works (Expected)
key as string; // Doesn't work (Expected)
key as number; // Doesn't work (Expected)
// ...
const sym = Symbol();
sym as symbol; // Works (Expected)
sym as string; // Doesn't work (Expected)
sym as number; // Doesn't work (Expected)
// ...🙁 Actual behavior
Interfaces that extend Symbol(e.g. InjectionKey) can't be used as symbol directly although they can be explicitly cast.
🙂 Expected behavior
Interfaces that extend Symbol can be used as symbol, which includes being used as index types.
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug