-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a test package using stable/preview types
This package intentionally does *not* have any of the runtime config or dependencies; it only needs `ember-source` and the Glint packages to be able to verify that type checking works correctly using the types published as part of the `ember-source` package. An annoying exception: we include the ESLint deps since we run ESLint from the root. We might be able to fix that in the future, but for now this unblocks things. This package also includes a check to make sure that this test package is *not* accidentally (read: via incorrect dependency hoisting) getting the DT types.
- Loading branch information
1 parent
dfcac1f
commit 86975ef
Showing
49 changed files
with
696 additions
and
6 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Compiled output | ||
/packages/*/lib | ||
/test-packages/*/lib | ||
/packages/scripts/bin | ||
dist/ | ||
|
||
|
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,4 @@ | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
import type { ComputedPropertyMarker } from '@ember/object/-private/types'; | ||
expectTypeOf<ComputedPropertyMarker<unknown>>().not.toBeUnknown(); |
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,25 @@ | ||
# unconventional js | ||
/blueprints/*/files/ | ||
/vendor/ | ||
|
||
# compiled output | ||
/dist/ | ||
/tmp/ | ||
|
||
# dependencies | ||
/bower_components/ | ||
/node_modules/ | ||
|
||
# misc | ||
/coverage/ | ||
!.* | ||
.*/ | ||
.eslintcache | ||
|
||
# ember-try | ||
/.node_modules.ember-try/ | ||
/bower.json.ember-try | ||
/npm-shrinkwrap.json.ember-try | ||
/package.json.ember-try | ||
/package-lock.json.ember-try | ||
/yarn.lock.ember-try |
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,56 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
legacyDecorators: true, | ||
}, | ||
}, | ||
plugins: ['ember', '@typescript-eslint'], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:ember/recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
], | ||
env: { | ||
browser: true, | ||
}, | ||
rules: { | ||
'@typescript-eslint/no-empty-interface': 'off', | ||
}, | ||
overrides: [ | ||
// node files | ||
{ | ||
files: [ | ||
'.eslintrc.js', | ||
'.template-lintrc.js', | ||
'ember-cli-build.js', | ||
'testem.js', | ||
'blueprints/*/index.js', | ||
'config/**/*.js', | ||
'lib/*/index.js', | ||
'server/**/*.js', | ||
], | ||
parserOptions: { | ||
sourceType: 'script', | ||
}, | ||
env: { | ||
browser: false, | ||
node: true, | ||
}, | ||
plugins: ['node'], | ||
extends: ['plugin:node/recommended'], | ||
rules: { | ||
// this can be removed once the following is fixed | ||
// https://github.com/mysticatea/eslint-plugin-node/issues/77 | ||
'node/no-unpublished-require': 'off', | ||
'@typescript-eslint/no-var-requires': 'off', | ||
}, | ||
}, | ||
], | ||
}; |
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,3 @@ | ||
# ts-ember-preview-types | ||
|
||
This application demonstrates the usage of glint in an Ember project with the Ember preview types. |
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,12 @@ | ||
import Application from '@ember/application'; | ||
import Resolver from 'ember-resolver'; | ||
import loadInitializers from 'ember-load-initializers'; | ||
import config from 'ts-ember-app/config/environment'; | ||
|
||
export default class App extends Application { | ||
modulePrefix = config.modulePrefix; | ||
podModulePrefix = config.podModulePrefix; | ||
Resolver = Resolver; | ||
} | ||
|
||
loadInitializers(App, config.modulePrefix); |
Empty file.
4 changes: 4 additions & 0 deletions
4
test-packages/ts-ember-preview-types/app/components/bar/index.hbs
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,4 @@ | ||
{{this.name}}-{{@grault}} | ||
|
||
{{! @glint-expect-error: invalid arg }} | ||
{{@waldo}} |
19 changes: 19 additions & 0 deletions
19
test-packages/ts-ember-preview-types/app/components/bar/index.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,19 @@ | ||
// eslint-disable-next-line ember/no-classic-components | ||
import Component from '@ember/component'; | ||
|
||
export interface BarSignature { | ||
Args: { | ||
grault: number; | ||
}; | ||
} | ||
|
||
// eslint-disable-next-line ember/require-tagless-components | ||
export default class Bar extends Component<BarSignature> { | ||
name = 'BAR'; | ||
} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
Bar: typeof Bar; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
test-packages/ts-ember-preview-types/app/components/ember-component.hbs
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 @@ | ||
<div ...attributes id={{unique-id}}> | ||
{{this.required}} | ||
{{this.optional}} | ||
{{this.hasDefault}} | ||
|
||
{{@required}} | ||
{{@optional}} | ||
{{@hasDefault}} | ||
|
||
{{!-- | ||
This pair of checks needs to work in this app, which uses the preview/stable | ||
types, and the ts-ember-app types app which uses legacy DT types. | ||
--}} | ||
{{get this "required"}} | ||
|
||
{{! @glint-expect-error: non-existent property }} | ||
{{get this "unrelated"}} | ||
</div> | ||
|
||
{{#if this.showFunctionHelpers}} | ||
{{! @glint-expect-error: missing arg }} | ||
{{this.isLongString}} | ||
|
||
{{! @glint-expect-error: wrong arg type }} | ||
{{this.isLongString 123}} | ||
|
||
{{this.isLongString 'hi'}} | ||
{{/if}} |
38 changes: 38 additions & 0 deletions
38
test-packages/ts-ember-preview-types/app/components/ember-component.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,38 @@ | ||
/* eslint-disable ember/no-classic-components, ember/require-tagless-components */ | ||
import Component from '@ember/component'; | ||
|
||
export interface EmberComponentArgs { | ||
required: string; | ||
hasDefault?: string; | ||
optional?: number; | ||
} | ||
|
||
export interface EmberComponentSignature { | ||
Element: HTMLDivElement; | ||
Args: EmberComponentArgs; | ||
} | ||
|
||
export default interface EmberComponent extends EmberComponentArgs {} | ||
export default class EmberComponent extends Component<EmberComponentSignature> { | ||
public hasDefault = 'defaultValue'; | ||
public showFunctionHelpers = false; | ||
|
||
public isLongString(value: string): boolean { | ||
return value.length > 5; | ||
} | ||
|
||
public checkTypes(): unknown { | ||
const required: string = this.required; | ||
const hasDefault: string = this.hasDefault; | ||
const optional: number | undefined = this.optional; | ||
|
||
return { required, hasDefault, optional }; | ||
} | ||
} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
EmberComponent: typeof EmberComponent; | ||
'ember-component': typeof EmberComponent; | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
test-packages/ts-ember-preview-types/app/components/foo.hbs
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,99 @@ | ||
{{this.name}} | ||
|
||
{{! @glint-expect-error: invalid property }} | ||
{{this.corge}} | ||
|
||
<Bar @grault={{0}} /> | ||
|
||
<Bar | ||
{{! @glint-expect-error: wrong type }} | ||
@grault={{this.obj.a}} | ||
/> | ||
|
||
<Bar | ||
{{! @glint-expect-error: bad arg }} | ||
@fred={{2}} | ||
/> | ||
|
||
{{! @glint-expect-error: missing required arg }} | ||
<Bar /> | ||
|
||
<Baz /> | ||
|
||
<Qux /> | ||
|
||
<this.MaybeComponent @arg="hi" /> | ||
|
||
{{! @glint-expect-error: missing required arg }} | ||
<this.MaybeComponent /> | ||
|
||
{{! @glint-expect-error: missing required arg }} | ||
<EmberComponent /> | ||
|
||
<EmberComponent @required="req" /> | ||
|
||
<EmberComponent | ||
{{! @glint-expect-error: bad type for `required` }} | ||
@required={{1}} | ||
/> | ||
|
||
<EmberComponent @required="req" @optional={{1}} /> | ||
|
||
<EmberComponent | ||
@required="req" | ||
|
||
{{! @glint-expect-error: bad type for `optional` }} | ||
@optional="opt" | ||
/> | ||
|
||
<EmberComponent @required="req" @hasDefault="override" /> | ||
|
||
<EmberComponent | ||
@required="req" | ||
|
||
{{! @glint-expect-error: bad type for `hasDefault` }} | ||
@hasDefault={{false}} | ||
/> | ||
|
||
<EmberComponent @required="hi"> | ||
{{! @glint-expect-error: bad named block }} | ||
<:foo>hello</:foo> | ||
</EmberComponent> | ||
|
||
<WrapperComponent @value="req" as |WC|> | ||
<WC.InnerComponent @optional={{1}} class="custom" /> | ||
|
||
{{! should work, even though MaybeComponent might not be present }} | ||
<WC.MaybeComponent @key="hi" /> | ||
|
||
{{! @glint-expect-error: strings aren't invokable }} | ||
<WC.stringValue /> | ||
</WrapperComponent> | ||
|
||
{{repeat "foo" 3}} | ||
|
||
{{! @glint-expect-error: missing second arg }} | ||
{{repeat "foo"}} | ||
|
||
{{! @glint-expect-error: incorrect type for second arg }} | ||
{{repeat "foo" "bar"}} | ||
|
||
{{affix "fuel" prefix="re" suffix="ing"}} | ||
|
||
{{affix "fuel" prefix="re"}} | ||
|
||
{{affix "fuel" suffix="ing"}} | ||
|
||
{{affix "fuel"}} | ||
|
||
{{! @glint-expect-error: missing positional arg }} | ||
{{affix prefix="re" suffix="ing"}} | ||
|
||
{{! @glint-expect-error: extra positional arg }} | ||
{{affix "fuel" "up" prefix="re" suffix="ing"}} | ||
|
||
{{! @glint-expect-error: incorrect type for named arg }} | ||
{{affix "fuel" prefix=1 suffix="ing"}} | ||
|
||
{{! @glint-expect-error: incorrect named arg given }} | ||
{{affix "fuel" prefix="re" suff="ing"}} |
17 changes: 17 additions & 0 deletions
17
test-packages/ts-ember-preview-types/app/components/foo.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 @@ | ||
/* eslint-disable ember/no-classic-components, ember/require-tagless-components */ | ||
import Component from '@ember/component'; | ||
import { ComponentLike } from '@glint/template'; | ||
|
||
export default class Foo extends Component { | ||
name = 'FOO'; | ||
|
||
obj = { a: 'A', b: 'B', c: 1, 𝚪: '' }; | ||
|
||
MaybeComponent?: ComponentLike<{ Args: { arg: string } }>; | ||
} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
Foo: typeof Foo; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
test-packages/ts-ember-preview-types/app/components/js-component.hbs
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 @@ | ||
{{this.message}} |
5 changes: 5 additions & 0 deletions
5
test-packages/ts-ember-preview-types/app/components/js-component.js
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,5 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
export default class MyComponent extends Component { | ||
message = 'hi'; | ||
} |
7 changes: 7 additions & 0 deletions
7
test-packages/ts-ember-preview-types/app/components/nocheck-me.hbs
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,7 @@ | ||
{{! @glint-nocheck }} | ||
|
||
{{this.nothing}} | ||
|
||
<Bar /> | ||
|
||
{{repeat "foo"}} |
12 changes: 12 additions & 0 deletions
12
test-packages/ts-ember-preview-types/app/components/qux.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,12 @@ | ||
/* eslint-disable ember/no-classic-components, ember/require-tagless-components */ | ||
import Component from '@ember/component'; | ||
|
||
export default class Qux extends Component { | ||
name = 'QUX'; | ||
} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
Qux: typeof Qux; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
test-packages/ts-ember-preview-types/app/components/template-only-module.hbs
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 @@ | ||
{{@message}}, world |
16 changes: 16 additions & 0 deletions
16
test-packages/ts-ember-preview-types/app/components/template-only-module.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,16 @@ | ||
import templateOnlyComponent from '@ember/component/template-only'; | ||
|
||
interface TemplateOnlyModuleSignature { | ||
Args: { message: string }; | ||
Blocks: { default: [] }; | ||
} | ||
|
||
const TemplateOnlyModule = templateOnlyComponent<TemplateOnlyModuleSignature>(); | ||
|
||
export default TemplateOnlyModule; | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
TemplateOnlyModule: typeof TemplateOnlyModule; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
test-packages/ts-ember-preview-types/app/components/template-only.hbs
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,6 @@ | ||
<Foo /> | ||
|
||
{{this}} | ||
|
||
{{! @glint-expect-error }} | ||
{{@foo}} |
1 change: 1 addition & 0 deletions
1
test-packages/ts-ember-preview-types/app/components/test-cases/subclassing/child.hbs
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 @@ | ||
Hello! |
Oops, something went wrong.