Closed

Description
Suggestion
π Search Terms
Multiple more than one index type property signature type specific member mapping TypeScript TS
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
Put further restrictions on index signatures being mapped to member types, driven by the type of the index signature. Basically add multiple index signatures to an interface that map different type keys to different type members. Hugely increases the power of index signatures. Blocked by #26797.
π Motivating Example
This:
export type ColorIdentifier =
`${string}.${string}`
| 'background'
| 'contrastActiveBorder' | 'contrastBorder' | 'focusBorder'
| 'descriptionForeground' | 'errorForeground' | 'foreground';
export type ThemeScopeKey = `[${string}]`;
export interface IThemeScopedColorCustomizations {
[colorId: ColorIdentifier]: string;
}
export interface IColorCustomizations {
[colorIdOrThemeScope: ColorIdentifier | ThemeScopeKey]: IThemeScopedColorCustomizations | string;
}
Could be more accurately specified as:
export type ColorIdentifier =
`${string}.${string}`
| 'background'
| 'contrastActiveBorder' | 'contrastBorder' | 'focusBorder'
| 'descriptionForeground' | 'errorForeground' | 'foreground';
export type ThemeScopeKey = `[${string}]`;
export interface IThemeScopedColorCustomizations {
[colorId: ColorIdentifier]: string;
}
export interface IColorCustomizations {
[colorId: ColorIdentifier]: string;
[themeScope: ThemeScopeKey]: IThemeScopedColorCustomizations;
}
π» Use Cases
The vscode
repo is full of interface collections that could make immediate use of this..
Metadata
Metadata
Assignees
Labels
No labels