-
Notifications
You must be signed in to change notification settings - Fork 82
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
Color space specific accessors do not work in typescript #381
Comments
The best idea I can think of is to change the The property on color.c! *= 1.2;
// ^ non-null assertion required, since color.c must be defined to multiply it That also doesn't change the fact that something like this would be allowed: color.foobar = 123; // allowed, since 123 satisfies `number | undefined` |
@MysteryBlokHed Since the However, since TypeScript classes can't have index signatures, I'm honestly not sure how to implement this on |
Right, I forgot about that. I'm not sure that there's a good way to get around that, so the best option might just be to manually add a property for every possible space coordinate. |
Surely that can't be the only way? How do you describe an object that is a proxy and can truly accept arbitrary properties then? |
Usually you could use something like this, which would allow any key of type interface Example {
[key: string]: number;
} The problem is that the types of all other properties in the object also have to fit in that type. If you try to add something like As far as I can tell, this is a deliberate choice by the TypeScript team and there isn't a good way around it. I'd definitely prefer to do it like this since it's a lot easier to maintain (i.e. no need to change the type definitions if new coordinate names are ever required), but I don't know if that's possible. |
I see. If we do have to explicitly list all color spaces and coordinate names, I think it's a much better strategy to do it via a build script rather than having to manually keep things in sync. But even then, it kinda breaks the whole extensibility argument — how would someone else adding an ad hoc color space extend the definition? |
I wonder if there would be value in posting about our use case to the TS repo so they could be aware of use cases like this. |
Coordinates of the color's color space are available without a prefix:
This triggers an error:
Property 'l' does not exist on type 'Color'.
The text was updated successfully, but these errors were encountered: