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

Future @ember/component types #19948

Merged
merged 6 commits into from
Feb 24, 2022
Merged

Conversation

wagenet
Copy link
Member

@wagenet wagenet commented Feb 7, 2022

No description provided.

@wagenet wagenet force-pushed the ember-component-types branch 3 times, most recently from 012a950 to 8e3a20b Compare February 10, 2022 17:16
@wagenet wagenet force-pushed the ember-component-types branch 2 times, most recently from ed8f5e7 to bdb6580 Compare February 18, 2022 00:12
Copy link
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

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

👍🏼 overall, couple small tweaks and then let's ship it.


attributeBindings?: Array<string>;
}
class Component
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a (small) runtime risk here, if I remember correctly: there are some hazards around zebra-striping with classic classes. 🦓 CC @wycats @pzuraq @rwjblue @chancancode – I don’t remember what the issue was, but I do remember that we recommended against “zebra-striping” within chains, in the “it should work, 99% of the time, if you dot all your i’s and cross all your t’s but it’s easy to just not zebra-stripe” bucket. Does anyone remember the details, and if so is it an ongoing concern such that we shouldn’t do this conversion?

Copy link
Contributor

Choose a reason for hiding this comment

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

To elaborate: the problem isn't internal, but for external consumers, since we currently still document Component.extend({ ... }) as the preferred way to define a Classic component.

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that some properties passed in extend won't override properties on the base class. I'll investigate these cases.

packages/@ember/-internals/glimmer/lib/helper.ts Outdated Show resolved Hide resolved
renderer: Renderer;
}

export { CoreView as default };
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not export default CoreView;?

Comment on lines 18 to 19
// Glint would help with this
declare args: { number: number };
Copy link
Contributor

Choose a reason for hiding this comment

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

This is for EmberComponent, right? Maybe just make some nonsense here that isn't args to avoid future confusion?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yeah, that's right. I always get them mixed up 😬

Copy link
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

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

This should be the last bucket of fixes for this round—thank you for driving this forward.

@@ -1,3 +1,6 @@
import { Mixin } from '@ember/-internals/metal';

export default class ActionHandler extends Mixin {}
export default class ActionHandler extends Mixin {
actions?: Record<string, (...args: unknown[]) => void>;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Does it have to return void (i.e. will anything else be thrown away anyway)? I think the answer is no, it can return anything. The type-checker will more or less shrug at it I think, but it should probably be unknown.

  2. I don't think the arguments will type check in practice either. 🤔 playground For types like this, unknown[] is usually wrong for arguments, because it means subclasses can never have narrower types in the function parameters than than, because it breaks assignability/Liskov substitution/variance rules (whichever way is easiest to think about it for you; they all boil down to the same issue here).

Net, the type should probably be:

Suggested change
actions?: Record<string, (...args: unknown[]) => void>;
actions?: Record<string, (...args: any[]) => unknown>;

(Technically, ...args: never[] is the "right" answer here, because all functions are valid super types of that, since never is the "bottom" type… but that confuses the heck out of people. And reasonably so.)

Comment on lines 14 to 16
export type EmberClassConstructor<T> = new (owner: Owner) => T;

type MergeArray<Arr extends any[]> = Arr extends [infer T, ...infer Rest]
export type MergeArray<Arr extends any[]> = Arr extends [infer T, ...infer Rest]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these also get @internal?

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems like it.

@@ -42,7 +47,7 @@ const CoreView = FrameworkObject.extend(Evented, ActionHandler, {
*/
parentView: null,

instrumentDetails(hash) {
instrumentDetails(hash: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Fine to do a follow-on pass here, but would Record<string, unknown> work as a first pass?

@wagenet wagenet merged commit 205075c into emberjs:master Feb 24, 2022
@chriskrycho chriskrycho mentioned this pull request Feb 24, 2022
nevilm-lt pushed a commit to nevilm-lt/ember.js that referenced this pull request Apr 22, 2022
nevilm-lt pushed a commit to nevilm-lt/ember.js that referenced this pull request Apr 22, 2022
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.

2 participants