-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
createEntity could return a stronger type #156
Comments
Thanks for the issue! I assume we're talking about the current state of the I was inferring the type from the entity passed into (If you have other ideas, please let me know!) |
Yes I was referring to whatever the latest version is on the main branch.
Yes I had a brief go at trying to do a PR for this by taking in a definable type into /**
* A RegisteredEntityWith is a RegisteredEntity (see above) but is also guaranteed to have certain components
*/
export type RegisteredEntityWith<
TEntity extends IEntity,
TComponentNames extends keyof TEntity
> = TEntity & Required<Pick<TEntity, TComponentNames>> & MiniplexComponent<TEntity>
public createEntity<TInput extends T>(entity: TInput): RegisteredEntityWith<T, keyof TInput> {
... But I was getting this error: As you say, maybe satisfies in 4.9 will fix it. |
I've done some experimenting. Not sure if |
A quick update, this is coming with the upcoming Miniplex 2.0 release (beta soon.) It is still unclear if TS will still throw a warning if extra properties are added when the type extends the world entity type; some recent experiments with this have shown very weird results that don't make it obvious what the intended behavior of TS is. Having said that, even if TS allows extra props to live on a type that extends another type, losing his kind of checking against extra props is an acceptable compromise if it means So, I'm adding this issue to the "2.0" milestone and closing it. Thanks! |
A quick update: it's been confirmed that TS should not display a warning for extra props, and that the intermittent instances of it still doing so is a bug. Still, I'm going to go ahead and ship this change with 2.0. It will mean that the objects returned by |
Because after you
createEntity
you guarantee that certain components are going to be there you could return the type fromcreateEntity
with "required" components.For now I am hacking this with an "as", but it would be nice is that wasnt needed as it could be inferred from the input to
createEntity
:where:
so then we can do this:
Thoughts? Or is it better to always have the user assume at than entity's components might not be there?
The text was updated successfully, but these errors were encountered: