-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic constraint with type list #2099
Comments
In order to be considered, we need suggestions to have at least some motivating use cases, examples of desired usage, examples of things that would be / would not be errors and why, etc.. We don't have resources to ask clarifying questions teasing out what these things mean. |
One of use cases is the following: interface KeyValueBase<K> {
f(): K;
}
interface KeyValue<K is number|string, V> extends KeyValueBase<K> {
[key: K]: V
} The key type must be string or number , it is impossible to define this generic right now. |
You could also use a type alias. type Key = number | string;
interface KeyValueBase {
f(): Key;
}
interface KeyValue extends KeyValueBase {
[key: Key]: V
} |
@DanielRosenwasser It is not the same since I don't know the exact type. |
Object indexer is the perfect example and use case for |
@DanielRosenwasser And btw even when using type aliasing TSLint still throws an error. |
One issue I had is with
I understand it won't work for everything (objects that aren't strictly used as maps), so it would probably be better to just have your own "wrapper function" around Object.entries, but I thought I'd mention it in case it helps anyone else who finds this issue. |
It is a generalization of #2049 .
I would like to see generic specifying concrete types:
The text was updated successfully, but these errors were encountered: