Skip to content

[@ember/object]: Make ObjectProxy content generic.#32770

Closed
jviney wants to merge 1 commit intoDefinitelyTyped:masterfrom
jviney:master
Closed

[@ember/object]: Make ObjectProxy content generic.#32770
jviney wants to merge 1 commit intoDefinitelyTyped:masterfrom
jviney:master

Conversation

@jviney
Copy link
Copy Markdown
Contributor

@jviney jviney commented Feb 5, 2019

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

Select one of these and delete the others:

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: <>
  • Increase the version number in the header if appropriate.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }.

@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Feb 5, 2019

@jviney Thank you for submitting this PR!

🔔 @mike-north - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Feb 5, 2019

@jviney The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@jviney
Copy link
Copy Markdown
Contributor Author

jviney commented Feb 5, 2019

I don't think the test failures are related to these changes. The same tests fail for typescript@next on master when I run them locally.

@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Feb 5, 2019

@jviney The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

assertType<AllowUndefined<Foo>>(instance.getProperties("fooProp1", "fooProp2"));

assertType<AllowUndefined<Foo>>(instance.getProperties(["fooProp1", "fooProp2"]));
instance.getProperties(["fooProp1", "unknownProperty"]); // $ExpectError
Copy link
Copy Markdown
Contributor

@mike-north mike-north Feb 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests that involve using the inner scope of your ObjectProxy subclasses, so we can make sure that this['foo'] works properly (i.e., try to use this.get from within a subclass method).

Please also see what happens with private class fields (they may or may not work, but I'm interested in seeing what happens).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a subclass methods accessing this.get and this.getProperties. Appear to work ok.

Not sure what you are getting at with the private class field. I added one to the ObjectProxy subclass, which fails when accessed by .get as you would expect.

): Pick<UnwrapComputedPropertyGettersUndefined<T>, K>;
getProperties<K extends keyof T>(
...list: K[]
): Pick<UnwrapComputedPropertyGettersUndefined<T>, K>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both get and getProperties seem to lack support for a property chain

Example:

const { 'chapters.length': numChapters } = book.getProperties('chapters.length');

please make sure to add tests for these cases too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh - are property chains like this supported with typescript? I wasn't aware that there was away to extract the expected type out of the chapters.length string.

I can't see any existing tests for getProperties that demonstrate this working with a plain EmberObject.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh - are property chains like this supported with typescript? I wasn't aware that there was away to extract the expected type out of the chapters.length string.

It will not type-check nicely, but it's absolutely part of Ember's public API (which is what these types are intended to describe).

As you've pointed out, we seem to be missing property chain access in other places, although this is where we have support for chains as dependent keys while defining computed properties

(
k1: string,
k2: string,
k3: string,
k4: string,
k5: string,
k6: string,
k7: string,
...rest: any[]
): ComputedProperty<any>;

Copy link
Copy Markdown
Contributor Author

@jviney jviney Feb 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed this had been left out deliberately, because if you add them you lose the type checking for the properties of the main object.

Currently .get('unknownProperty') will cause a TS error. But if we add overloads that accept any string in order to support property chains, we lose that type checking because the overload will always match.

Because of this, I don't tend to use property chaining with .get any more. I prefer to sacrifice a few extra lines of code to check any intermediaries for null/undefined rather than sacrifice type safety.

The only workaround I can think of is if TS supports a string type that includes a regex match to check it contains a . character, in which case you could match the overloads to support property chaining without losing the other type checking. But I very much doubt that's possible.

Thoughts?

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Feb 6, 2019
@typescript-bot
Copy link
Copy Markdown
Contributor

@jviney The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Feb 6, 2019

@jviney The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Copy link
Copy Markdown
Contributor

@mike-north mike-north left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving the ember types! This looks good to me, assuming relevant tests are passing

@typescript-bot typescript-bot added the Owner Approved A listed owner of this package signed off on the pull request. label Feb 6, 2019
@typescript-bot
Copy link
Copy Markdown
Contributor

@jviney I haven't seen anything from you in a while and this PR currently has problems that prevent it from being merged. The PR will be closed tomorrow if there aren't new commits to fix the issues.

@jviney
Copy link
Copy Markdown
Contributor Author

jviney commented Feb 12, 2019

@mike-north Any comments on the property chains? Happy for this to be merged?

@mike-north
Copy link
Copy Markdown
Contributor

@RyanCavanaugh - @typescript-bot seems to be misbehaving. The "owner approved" tag should supersede the "revision needed" tag here

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Feb 13, 2019
@typescript-bot
Copy link
Copy Markdown
Contributor

@jviney To keep things tidy, we have to close PRs that aren't mergeable but don't have activity from their author. No worries, though - please open a new PR if you'd like to continue with this change. Thank you!

@mike-north
Copy link
Copy Markdown
Contributor

@RyanCavanaugh - this shouldn't have been closed. Seems like @typescript-bot is in need of some maintenance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Abandoned This PR had no activity for a long time, and is considered abandoned Owner Approved A listed owner of this package signed off on the pull request. Revision needed This PR needs code changes before it can be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants