[@ember/object]: Make ObjectProxy content generic.#32770
[@ember/object]: Make ObjectProxy content generic.#32770jviney wants to merge 1 commit intoDefinitelyTyped:masterfrom jviney:master
Conversation
|
@jviney Thank you for submitting this PR! 🔔 @mike-north - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
|
@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! |
|
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. |
|
@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! |
types/ember__object/test/proxy.ts
Outdated
| assertType<AllowUndefined<Foo>>(instance.getProperties("fooProp1", "fooProp2")); | ||
|
|
||
| assertType<AllowUndefined<Foo>>(instance.getProperties(["fooProp1", "fooProp2"])); | ||
| instance.getProperties(["fooProp1", "unknownProperty"]); // $ExpectError |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
types/ember__object/proxy.d.ts
Outdated
| ): Pick<UnwrapComputedPropertyGettersUndefined<T>, K>; | ||
| getProperties<K extends keyof T>( | ||
| ...list: K[] | ||
| ): Pick<UnwrapComputedPropertyGettersUndefined<T>, K>; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.lengthstring.
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
DefinitelyTyped/types/ember__object/index.d.ts
Lines 63 to 72 in 9a080ec
There was a problem hiding this comment.
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?
|
@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! |
…r EmberObject getters.
|
@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! |
mike-north
left a comment
There was a problem hiding this comment.
Thanks for improving the ember types! This looks good to me, assuming relevant tests are passing
|
@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. |
|
@mike-north Any comments on the property chains? Happy for this to be merged? |
|
@RyanCavanaugh - @typescript-bot seems to be misbehaving. The "owner approved" tag should supersede the "revision needed" tag here |
|
@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! |
|
@RyanCavanaugh - this shouldn't have been closed. Seems like @typescript-bot is in need of some maintenance |
Please fill in this template.
npm test.)npm run lint package-name(ortscif notslint.jsonis present).Select one of these and delete the others:
If changing an existing definition:
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }.