Git Product home page Git Product logo

Comments (8)

hugebdu avatar hugebdu commented on July 26, 2024 1

@Hookyns you're blazingly fast! )))
Thanks a lot, will take a look.

from tst-reflect.

hugebdu avatar hugebdu commented on July 26, 2024 1

@Hookyns confirmed!
Thanks a lot!
Great lib, really like the idea, will see if I can use it for my use case (ORM schema definition via TS)

from tst-reflect.

Hookyns avatar Hookyns commented on July 26, 2024

Hello,

kind Container is mainly for type operations such as Union and Intersection (Type1 | Type2 & Type3), it is not intended for enums, but yeah, it makes sense it fell to this kind.
I think I haven't test enums yet; I think the new Enum kind will be needed with new special handlers for that.

Now it generates

___tst_reflect.Type.store.set(21838, {k: 6, n: "", v: 0});
___tst_reflect.Type.store.set(21839, {k: 6, n: "", v: 1});
___tst_reflect.Type.store.set(21837, {
	k: 3,
	types: [___tst_reflect.Type.store.get(21838), ___tst_reflect.Type.store.get(21839)],
	union: true,
	inter: false
});

Which is union of literals. There are values but no names,.. its under Type.types

What do you expect in Enum Type?

  • name of the enum
  • and enum itself? Or list of entries ([ {property: "Single", value: 1}, { ... } ]) or simple object ({ "Married":0, "Single":1 })?

Enum is transpiled as:

var SomeEnum;
(function (SomeEnum) {
    SomeEnum[SomeEnum["One"] = 0] = "One";
    SomeEnum[SomeEnum["Two"] = 1] = "Two";
})(SomeEnum || (SomeEnum = {}));

which gives you everything.. so reference to that enum should be enough.

from tst-reflect.

hugebdu avatar hugebdu commented on July 26, 2024

indeed, reference to enum sounds good, but a discriminator is required to know it's an enum (maybe TypeKind.Enum?)

from tst-reflect.

Hookyns avatar Hookyns commented on July 26, 2024

Okay, I've pushed implementation into same branch (https://github.com/Hookyns/ts-reflection/tree/feature/refactored-stores).

There is no reference to the real enum, it was quite problematic, because those enums can be in private modules (not exported) etc. and the enums would be useless without references.

So I add

  • Enum kind,
  • Type.isEnum(): boolean,
  • Type.getEnum(): EnumInfo

EnumInfo:

interface EnumInfo
{
	/**
	 * Get enum enumerators/items (keys).
	 */
	getEnumerators(): string[];

	/**
	 * Get values.
	 */
	getValues(): any[];

	/**
	 * Get enum entries (key:value pairs).
	 */
	getEntries(): Array<readonly [enumeratorName: string, value: any]>;
}

from tst-reflect.

Hookyns avatar Hookyns commented on July 26, 2024

I've published new versions of packages with implementation:

[email protected]
[email protected]

from tst-reflect.

Hookyns avatar Hookyns commented on July 26, 2024

I thank you for this issue!

Feel free to create another issues if you find something. 🙂

from tst-reflect.

hugebdu avatar hugebdu commented on July 26, 2024

just did 😄

from tst-reflect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.