-
Notifications
You must be signed in to change notification settings - Fork 378
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
More principled portrayal of traits in various places, and more #3276
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Workarounds for this error: TS2589: Type instantiation is excessively deep and possibly infinite.
@steve9164 the TypeScript 3.4 error you reported on slack is now fixed. |
This was referenced Apr 15, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TypeConditionals
andTypeModifiers
with some utilities for manipulating types and making queries about them. Among other uses, these can be combined withTypeChecks.ts
to "test" types; a compilation failure is a test failure. Seetest/Types/ModelPropertiesFromTraitsSpec.ts
for an example of type tests.getOrCreateStratum
because TypeScript currently does not intersect return types in functions in intersected types (Merge overloads that only differ by return type when intersecting microsoft/TypeScript#30520). Instead, there are newsetTrait
andgetTrait
methods onModel
.hasTraits
, which serves as both a runtime check that a Model has a particular trait and a TypeScript type guard that allowing type-safe access to those traits. This eliminates the need to write a bunch of little interfaces likeAdjustableOpacity
.StratumFromTraits
,FlattenedFromTraits
, andModelPropertiesFromTraits
. These all take a traits class and produce a new type describing the interface to a single stratum, theflattened
property, and theModel
itself, respectively. The portrayal of traits in these three scenarios are different in terms of default values (only model properties have a default) and writability (only stratum traits are writable). These three types are tricky recursive types, and I kept getting them subtly wrong. So I've added tests for them and now I'm pretty sure they're right.Fixes #3291
Fixes #3292