-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Future public types for @ember/component
- Loading branch information
Showing
10 changed files
with
177 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { capabilities } from '@ember/component'; | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
expectTypeOf(capabilities('3.13')).toMatchTypeOf<{ | ||
asyncLifecycleCallbacks?: boolean | undefined; | ||
destructor?: boolean | undefined; | ||
updateHook?: boolean | undefined; | ||
}>(); | ||
|
||
capabilities('3.13', { asyncLifecycleCallbacks: true }); | ||
capabilities('3.4', { asyncLifecycleCallbacks: true }); | ||
|
||
// @ts-expect-error invalid capabilities | ||
capabilities('3.13', { asyncLifecycleCallbacks: 1 }); | ||
// @ts-expect-error invalid verison | ||
capabilities('3.12'); |
8 changes: 8 additions & 0 deletions
8
packages/@ember/component/type-tests/get-component-template.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getComponentTemplate } from '@ember/component'; | ||
import { TemplateFactory } from '@glimmer/interfaces'; | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
expectTypeOf(getComponentTemplate({})).toEqualTypeOf<TemplateFactory | undefined>(); | ||
|
||
// @ts-expect-error requires param | ||
getComponentTemplate(); |
18 changes: 18 additions & 0 deletions
18
packages/@ember/component/type-tests/helper/helper.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { HelperFactory, SimpleHelper } from '@ember/-internals/glimmer/lib/helper'; | ||
import { helper } from '@ember/component/helper'; | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
// NOTE: The types for `helper` are not actually safe. Glint helps with this. | ||
|
||
let myHelper = helper(function ([cents]: [number], { currency }: { currency: string }) { | ||
return `${currency}${cents * 0.01}`; | ||
}); | ||
expectTypeOf(myHelper).toEqualTypeOf< | ||
HelperFactory<SimpleHelper<string, [number], { currency: string }>> | ||
>(); | ||
|
||
// @ts-expect-error invalid named params | ||
helper(function ([cents]: [number], named: number) {}); | ||
|
||
// @ts-expect-error invalid params | ||
helper(function (params: number) {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { FrameworkObject } from '@ember/-internals/runtime'; | ||
import Helper from '@ember/component/helper'; | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
// NOTE: The types for `compute` are not actually safe. Glint helps with this. | ||
|
||
let helper = new Helper(); | ||
|
||
expectTypeOf(helper).toMatchTypeOf<FrameworkObject>(); | ||
|
||
class MyHelper extends Helper { | ||
compute([cents]: [number], { currency }: { currency: string }) { | ||
return `${currency}${cents * 0.01}`; | ||
} | ||
} | ||
new MyHelper(); | ||
|
||
class NoHash extends Helper { | ||
compute([cents]: [number]): string { | ||
return `${cents * 0.01}`; | ||
} | ||
} | ||
new NoHash(); | ||
|
||
class NoParams extends Helper { | ||
compute(): string { | ||
return 'hello'; | ||
} | ||
} | ||
new NoParams(); | ||
|
||
class InvalidHelper extends Helper { | ||
// @ts-expect-error Invalid params | ||
compute(value: boolean): string { | ||
return String(value); | ||
} | ||
} | ||
new InvalidHelper(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/@ember/component/type-tests/set-component-manager.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Owner } from '@ember/-internals/owner'; | ||
import { setComponentManager } from '@ember/component'; | ||
import { ComponentManager } from '@glimmer/interfaces'; | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
// Obviously this is invalid, but it works for our purposes. | ||
let manager = {} as ComponentManager<unknown>; | ||
|
||
class Foo {} | ||
let foo = new Foo(); | ||
|
||
expectTypeOf(setComponentManager((_owner: Owner) => manager, foo)).toEqualTypeOf<Foo>(); | ||
|
||
// @ts-expect-error invalid callback | ||
setComponentManager(() => { | ||
return {}; | ||
}, foo); |
8 changes: 8 additions & 0 deletions
8
packages/@ember/component/type-tests/set-component-template.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { setComponentTemplate } from '@ember/component'; | ||
import { TemplateFactory } from '@glimmer/interfaces'; | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
// Good enough for testing | ||
let factory = {} as TemplateFactory; | ||
|
||
expectTypeOf(setComponentTemplate(factory, {})).toEqualTypeOf<object>(); |
11 changes: 11 additions & 0 deletions
11
packages/@ember/component/type-tests/template-only.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import templateOnlyComponent from '@ember/component/template-only'; | ||
import { TemplateOnlyComponentDefinition } from '@glimmer/runtime/dist/types/lib/component/template-only'; | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
expectTypeOf(templateOnlyComponent()).toEqualTypeOf<TemplateOnlyComponentDefinition>(); | ||
|
||
templateOnlyComponent('myModule'); | ||
templateOnlyComponent('myModule', 'myName'); | ||
|
||
// @ts-expect-error invalid params | ||
templateOnlyComponent(1); |