-
-
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.
[BUGFIX types] Add missing type declarations in the preview types for…
… @ember/template-compilation
- Loading branch information
1 parent
0c5518e
commit 9da91e8
Showing
3 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { precompileTemplate } from '@ember/template-compilation'; | ||
import { setComponentTemplate } from '@ember/component'; | ||
import templateOnly from '@ember/component/template-only'; | ||
|
||
import { expectTypeOf } from 'expect-type'; | ||
|
||
// Valid usages | ||
precompileTemplate(`Hello World`, { moduleName: 'foo' }); | ||
precompileTemplate(`Hello World`, { strictMode: true }); | ||
precompileTemplate(`Hello World`, { strictMode: false }); | ||
precompileTemplate(`Hello World`, { strictMode: true, scope: () => ({}) }); | ||
precompileTemplate(`Hello World`, { strictMode: true, scope: () => ({ setComponentTemplate }) }); | ||
precompileTemplate(`Hello World`, { strictMode: true, moduleName: 'hello', scope: () => ({}) }); | ||
|
||
// Integration, since this is the primary use case for precompileTemplate | ||
expectTypeOf(setComponentTemplate(precompileTemplate(`Hello World`), templateOnly())).toBeObject(); | ||
|
||
// @ts-expect-error scope must be a function | ||
precompileTemplate(`Hello World`, { strictMode: true, scope: {} }); | ||
|
||
// @ts-expect-error scope must return an object | ||
precompileTemplate(`Hello World`, { strictMode: true, scope: () => {} }); | ||
|
||
// @ts-expect-error scope must return an object and arrays are not the kind of object we want | ||
precompileTemplate(`Hello World`, { strictMode: true, scope: () => [] }); | ||
|
||
// @ts-expect-error scope has no purpose when strictMode is false | ||
precompileTemplate(`Hello World`, { strictMode: false, scope: () => ({}) }); |
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,26 @@ | ||
/** | ||
* References: | ||
* - https://github.com/emberjs/rfcs/pull/496 | ||
* - https://github.com/emberjs/rfcs/pull/779 | ||
*/ | ||
declare module '@ember/template-compilation' { | ||
interface TemplateFactory { | ||
__htmlbars_inline_precompile_template_factory: any; | ||
} | ||
|
||
type PrecompileTemplateOptions = | ||
| { | ||
strictMode?: false; | ||
moduleName?: string; | ||
} | ||
| { | ||
strictMode: true; | ||
moduleName?: string; | ||
scope?: () => Record<string, unknown>; | ||
}; | ||
|
||
export function precompileTemplate( | ||
template: string, | ||
options?: PrecompileTemplateOptions | ||
): TemplateFactory; | ||
} |
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