-
Notifications
You must be signed in to change notification settings - Fork 561
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
Refactored type and property helpers #6721
base: main
Are you sure you want to change the base?
Conversation
Putting this into draft as it seems I'm missing a few |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to go for me 👍 Nice refactoring Kraen 🙂
PropertyHelpers, | ||
PropertyOptions, | ||
} from "./property-accessors/types"; | ||
import { createIntPropertyAccessor } from "./property-accessors/Int"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could move this up with the other create
imports 👍
import { createDictionaryPropertyAccessor } from "./property-accessors/Dictionary"; | ||
import { createDefaultPropertyAccessor } from "./property-accessors/default"; | ||
import { createSetPropertyAccessor } from "./property-accessors/Set"; | ||
import { createMixedPropertyAccessor } from "./property-accessors/Mixed"; | ||
import { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the pattern in TypeHelpers.ts
when there are many related imports in between.
import { | |
import { |
function createUnsupportedTypeHelpers(): TypeHelpers { | ||
return { | ||
fromBinding() { | ||
throw new Error("Not yet supported"); | ||
}, | ||
toBinding() { | ||
throw new Error("Not yet supported"); | ||
}, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Would it make sense to have a type-helpers/unsupported.ts
? 🤔
}; | ||
} | ||
|
||
import type { PropertyAccessor, PropertyHelpers, PropertyOptions } from "./types"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this accidentally got placed here instead of at the top.
import { createUuidTypeHelpers } from "./type-helpers/Uuid"; | ||
import { createArrayTypeHelpers } from "./type-helpers/Array"; | ||
|
||
import type { TypeHelpers, TypeOptions } from "./type-helpers/types"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type
may be redundant for these imports. (If updating, there are more occurrences.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I want to leverage the import type
more to avoid circular dependencies at runtime (as these imports are stripped from JS files when running tsc
). I still have an outstanding task of fixing these circular imports which got leaked into the developers bundling process, after we migrated away from Rollup.
That being said, the TypeScript compiler seems pretty good at shaking off these type-only imports, even if the type
keyword isn't used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you mention, I thought TS handled that implicitly when the import itself was a type
as in this case. But are you saying that you prefer to still be explicit to be certain?
Co-authored-by: LJ <81748770+elle-j@users.noreply.github.com>
70fd921
to
80e5d87
Compare
What, How & Why?
This refactors the type and property helpers into multiple files.
I want to move away from the "internal-pattern" to get rid of the circular reference warnings, which I somewhat started here and I'll have to do a separate (massive) PR later to complete that.
At some point, I think it'll also be nice to move some of the functions introduced in #6613 into type specific property helpers.