Skip to content
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

Merged
merged 27 commits into from
Apr 14, 2019
Merged

Conversation

kring
Copy link
Member

@kring kring commented Apr 3, 2019

  • Added TypeConditionals and TypeModifiers with some utilities for manipulating types and making queries about them. Among other uses, these can be combined with TypeChecks.ts to "test" types; a compilation failure is a test failure. See test/Types/ModelPropertiesFromTraitsSpec.ts for an example of type tests.
  • Removed 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 new setTrait and getTrait methods on Model.
  • Added 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 like AdjustableOpacity.
  • Re-added support for default values for traits.
  • Added StratumFromTraits, FlattenedFromTraits, and ModelPropertiesFromTraits. These all take a traits class and produce a new type describing the interface to a single stratum, the flattened property, and the Model 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.
  • Other minor odds and ends and cleanup.

Fixes #3291
Fixes #3292

@kring
Copy link
Member Author

kring commented Apr 14, 2019

@steve9164 the TypeScript 3.4 error you reported on slack is now fixed.

@kring kring merged commit 6faccd7 into mobx Apr 14, 2019
@kring kring deleted the kr-mobx branch April 14, 2019 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant