question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vega-typings enum discussion

See original GitHub issue

Hi everyone, I’d like to start a discussion about the possibility of using enums in vega-typings.

There are quite a few types that are union types of a bunch of string constants. Examples: https://github.com/vega/vega/blob/master/packages/vega-typings/types/spec/marktype.d.ts https://github.com/vega/vega/blob/8941b87cbfd678618d76b6e0a99aa5f77c43abc3/packages/vega-typings/types/spec/scale.d.ts#L4

There are also some that almost conform to this pattern, but have additional members like SignalRefs.

For example: https://github.com/vega/vega/blob/8941b87cbfd678618d76b6e0a99aa5f77c43abc3/packages/vega-typings/types/spec/scale.d.ts#L29

This SortOrder example makes me think that we should switch to enum types for this use case, because in working on Lyra I noticed that if we adopt vega-typings, we currently have to either 1) use raw string literals or 2) keep a separate struct in Lyra to store the literal values. These will both easily go out of sync with vega-typings (they already have, because the SortOrder constants changed from asc to ascending and desc to descending between Vega 2 and today).

The benefit of using enum: they provide the type and the values at once. So, you could define an enum SortOrderValues and use SortOrderValues.Asc without worrying about the underlying constant, and you can also type variables as x: SortOrderValues to get the behavior we already have with union types.

tl;dr what if we e.g. replaced SortOrder with something like

export enum SortOrderValues {
  Asc = 'ascending',
  Desc = 'descending'
}

export type SortOrder = SortOrderValues | SignalRef;

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
domoritzcommented, Feb 14, 2019

Should we close this issue for now?

0reactions
kanitwcommented, Feb 13, 2019

Oh right, I wonder if the same approach works with the transformer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating an Enum SuperType - Oracle Communities
So I have an Enum public enum Example1 { one(1, "one"), two(2, "two"); private int code; private String label; Example1(int code, ...
Read more >
Open Source Used In CloudCenter SA 5.2.2 - Cisco
1.1231 vega-typings 0.2.15 ... 1.1315 python-enum 1.0.4 1.el7 ... Licensor for the purpose of discussing and improving the Work, but excluding communication ...
Read more >
If Vertica kafka Utilities support parsing Avro Enum type data?
I use a kafka schedular to parse messages from kafka with KafkaAVROParser, but the values can't be persisted into db table. Untitled picture.png....
Read more >
What is C++ Enum, And How to Use Enums in C++ - Simplilearn
It provides a way to define and group integral constants. It also makes the code easy to maintain and less complex. In this...
Read more >
Using Enumeration classes instead of enum types
NET Microservices Architecture for Containerized .NET Applications | Lear how you can use enumeration classes, instead of enums, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found