-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
Augment flag keys in ".flags" type definition #155
Comments
Correcting myself: |
Closing this as this somewhat duplicates: #165 (comment) Just a note, it may soon be possible to do something about this as the TypeScript 4.1 beta supports: type Getters<T> = {
[K in keyof T as `get${capitalize K}`]: () => T[K]
};
interface Person {
name: string;
age: number;
location: string;
}
type LazyPerson = Getters<Person>; If there would be a type CamelCase<K extends string> = `${Split<K, "-">[0]}${Capitalize<Split<K, "-">[1] | "">}
type CamelCasedProps<T> = {
[K in keyof T as CamelCase<K>]: () => T[K]
};
interface KebabCased {
"foo-bar": string;
foo: number;
}
type CamelCased = CamelCasedProps<KebabCased>; |
Actually, it is already possible: microsoft/TypeScript#40710 (comment) |
@voxpelli Should we reopen this? |
@sindresorhus Yeah, lets do it. So, this would rely on sindresorhus/type-fest#134 I'm thinking.
Unless of course one can publish these new types in a way that works with older TS versions, but I doubt it |
I'm ok with requiring TS 4.1 a couple of months after it has shipped. The benefits are worth it. |
Unfortunately this doesn't seems doable yet, but it is something that is discussed here it seems: microsoft/TypeScript#12754
So currently
.flags['foo-bar']
will have the same type as.unnormalizedFlags['foo-bar']
, whereas only the latter should have that, the former should have it's key augmented into.flags.fooBar
or at least have the errenousfoo-bar
key removed.I believe none of that is possible right now, but wanted to open an issue and track that it would be preferable, as that can then eg. tie into the discussions within TypeScript itself.
The text was updated successfully, but these errors were encountered: