Skip to content

Commit 115d89b

Browse files
Merge pull request #21524 from olenderhub/fix/classic-component-init-optional-arg
[BUGFIX] Allow CoreObject#init to be called with no arguments
2 parents 0da7476 + b11e9aa commit 115d89b

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎packages/@ember/object/core.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class CoreObject {
346346
@method init
347347
@public
348348
*/
349-
init(_properties: object | undefined) {}
349+
init(_properties?: object) {}
350350

351351
/**
352352
Defines the properties that will be concatenated from the superclass

‎type-tests/@ember/component-test/component.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ const component1 = Component.extend({
1717
},
1818
});
1919

20-
class AnotherComponent extends Component {
21-
name = '';
22-
23-
init() {
20+
class ClassicComponent extends Component {
21+
override init(): void {
2422
super.init();
2523
}
24+
}
25+
26+
class AnotherComponent extends Component {
27+
name = '';
2628

2729
hello(name: string) {
2830
this.set('name', name);

‎type-tests/ember/core-object.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ expectTypeOf(co1.isDestroying).toBeBoolean();
99
expectTypeOf(co1.destroy()).toEqualTypeOf<CoreObject>();
1010
expectTypeOf(co1.toString()).toBeString();
1111

12+
/** Subclasses may override init and call super.init() without arguments. */
13+
class CoreObjectWithInit extends CoreObject {
14+
override init(): void {
15+
super.init();
16+
}
17+
}
18+
1219
/** .create tests */
1320
const co2 = CoreObject.create();
1421
expectTypeOf(co2.isDestroyed).toBeBoolean();

0 commit comments

Comments
 (0)