Effect-TS / effect

An ecosystem of tools to build robust applications in TypeScript
https://effect.website
MIT License
6.11k stars 195 forks source link

Standard type extraction #2982

Open mikearnaldi opened 2 weeks ago

mikearnaldi commented 2 weeks ago

In Schema we now added ability to extract types like: typeof Person.Type that makes it really nice to get the types, the same should be applied to things such as tags so one can do typeof Service.Type and to Effect so that one can do typeof Effect.Success etc.

I do feel though that unless we prefix those fake properties somehow it can become confusing, one might argue that defining them in uppercase makes it clear that they are meant to be types and not real values.

This issue is to discuss on a standard.

cc @gcanti @tim-smart @IMax153 @datner @patroza @fubhy

patroza commented 2 weeks ago

So far I think that the capitalization is sufficient. Types are generally capitalized. Uppercase generally signifies constants. JSDoc should take care of the rest.

IMax153 commented 1 week ago

If we wanted to be even more pedantic, we could add a Type suffix, so:

Effect.SuccessType
Effect.ErrorType
Effect.ContextType

but to be honest I think this is unnecessary and overly verbose. I agree with @patroza that the capitalization should generally be sufficient, along with a JSDoc explaining what the value is intended to be used for.

tim-smart commented 1 week ago

One other option is a namespace:

typeof someEffect.Types.Success

But I think I prefer .Success etc directly on the type.

patroza commented 1 week ago

One other option is a namespace:

typeof someEffect.Types.Success

lol you mad.. can never have enough namespaces can we, we'd be back at square one: Effect.Effect.Success<typeof X>. then again it might be preferred over pre or suffixes, and it might address mikes concerns.

datner commented 1 week ago

while

typeof someEffect.Types.Success

would be the most obvious, the more nested it is the less benefit it has over Effect.Effect.Success<typeof someEffect> Like, if we just alias it to the module level then compared with an Effect.Success<typeof someEffect> it's barely any different.

It has to be

typeof someEffect.Success

if at all 🤔 (name pending, I only mean the nesting)