-
Notifications
You must be signed in to change notification settings - Fork 94
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
Simplify Extending Primitive Types #91
Comments
Agree with the thrust of this, just dropping in the additional context that they started out as struct types, and we moved to the current implementation to avoid people needing to type |
Maybe have a Const that is defined as StringType{}? |
I'm no longer working on this, but if memory serves the underlying problem here is that primitives are of an unexported In theory, primitives could be changed to their own types instead of being the unexported primitive type, but that would require them to be instantiated (including Primitives could be changed to their own types instead of being the unexported primitive type and a constant for each could be created, but what would the type/constant be named? Either the constant is named unintuitively for "normal" use or the type is named unintuitively for use as a base type implementation. The unexported I think my pitch would be to have a |
Reference: #91 Aliasing and function shadowing in the original `types` package should prevent most provider developer changes. The main exception is the newer type-specific `Typable` and `Valuable` interfaces were moved without a type alias. This should help developers find the necessary interfaces for custom types next to the base type implementations. The underlying implementation of the primitive types (`BoolType`, `Float64Type`, `Int64Type`, `NumberType`, and `StringType`) are now fully exported types instead of the unexported `primitive` type which was difficult to extend. The underlying value type creation functions were prefixed with New and the value types themselves were renamed to include Value at the end. This should prevent rough edges with the `String` value type since it conflicted with the `String()` method and could not be directly embedded easily.
Reference: #91 Aliasing and function shadowing in the original `types` package should prevent most provider developer changes. The main exception is the newer type-specific `Typable` and `Valuable` interfaces were moved without a type alias. This should help developers find the necessary interfaces for custom types next to the base type implementations. The underlying implementation of the primitive types (`BoolType`, `Float64Type`, `Int64Type`, `NumberType`, and `StringType`) are now fully exported types instead of the unexported `primitive` type which was difficult to extend. The underlying value type creation functions were prefixed with New and the value types themselves were renamed to include Value at the end. This should prevent rough edges with the `String` value type since it conflicted with the `String()` method and could not be directly embedded easily.
Similar to the above comment, a Maybe for the next major version, we can consider cleaning this up slightly, but this should make life easier for now. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Module version
Use-cases
Provider developers may wish to implement higher level types based off the primitive types in the current
types
package. For example, this may be a string-based attribute type that implements common validation checks on top.Attempted Solutions
Currently, this seems more difficult than it should be since these higher level types cannot extend
BoolType
,NumberType
, andStringType
. A current possible workaround can be seen in theinternal/testing/types
package, which reimplements those types as structures.Trying with type aliasing fails:
Creating a struct type (with pointer or concrete) fails:
Trying as a variable also sensibly fails:
Other current types, such as
ListType
,MapType
, andObjectType
are not affected as they are already structure types.Proposal
This functionality should be designed with a holistic view on custom types, as such it has been marked with the
design-doc
label to signify that extra documentation should be provided on decision making.One possible path forward would be to switch
BoolType
,NumberType
, andStringType
to structure types, similar to what is done in the currentinternal/testing/types
package.References
The text was updated successfully, but these errors were encountered: