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

Make it easier to avoid errors with vanilla tsc #248

Merged
merged 5 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unused-vars": ["warn", { "varsIgnorePattern": "^_" }],
"@typescript-eslint/ban-ts-comment": ["error", { "ts-ignore": "allow-with-description" }],
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ The language server can also enable your editor to provide other richer help, su

### With GlimmerX

To minimize spurious errors when typechecking with vanilla `tsc` or your editor's TypeScript integration, you should add `import '@glint/environment-glimmerx';` somewhere in your project's source or type declarations. You may also choose to disable TypeScript's "unused symbol" warnings in your editor, since `tsserver` won't understand that templates actually are using them.

#### Import Paths

In order for GlimmerX entities to be interpretable by Glint, you currently need to use Glint-specific import paths for `@glimmerx/modifier`, `@glimmerx/helper` and `@glimmerx/component`. Note that [this is not a long-term restriction](#environment-re-exports), but a temporary workaround for the current state of the ecosystem.
Expand Down Expand Up @@ -164,6 +166,8 @@ import type { TC } from '@glint/environment-glimmerx/component';

### With Ember.js

To minimize spurious errors when typechecking with vanilla `tsc` or your editor's TypeScript integration, you should add `import '@glint/environment-ember-loose';` somewhere in your project's source or type declarations. You may also choose to disable TypeScript's "unused symbol" warnings in your editor, since `tsserver` won't understand that templates actually are using them.

#### Import Paths

In order for GlimmerX entities to be interpretable by Glint, you currently need to use Glint-specific import paths for `@glimmer/component`, `@ember/component` and `ember-modifier`. Note that [this is not a long-term restriction](#environment-re-exports), but a temporary workaround for the current state of the ecosystem.
Expand Down
7 changes: 4 additions & 3 deletions packages/environment-ember-loose/-private/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Import the scaffolding for the template registry and our merged declarations
// Reference the scaffolding for the template registry and our merged declarations
// for third party modules so that vanilla TS will see those as long as authors
// have `import '@glint/environment-ember-loose'` somewhere in their project.
import type {} from '../registry';
import type {} from './dsl/integration-declarations';

/// <reference path="../registry/index.d.ts" />
/// <reference path="./dsl/integration-declarations.d.ts" />

export { ComponentSignature, ComponentLike, ComponentWithBoundArgs } from './utilities';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import '@glimmerx/component';
import { TemplateComponent } from '../../component';

// Declaring that `hbs` returns a `TemplateComponent` prevents vanilla `tsc` from freaking out when
// it sees code like `const MyThing: TC<Sig> = hbs...`. Glint itself will never see `hbs` get used, as
// it's transformed to the template DSL before typechecking.
declare module '@glimmerx/component' {
export function hbs(source: TemplateStringsArray): TemplateComponent<any>;
}
5 changes: 5 additions & 0 deletions packages/environment-glimmerx/-private/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Reference the scaffolding for our merged declarations for third party modules so
// that vanilla TS will see those as long as authors have
// `import '@glint/environment-glimmerx'` somewhere in their project.

/// <reference path="./dsl/integration-declarations.d.ts" />
2 changes: 2 additions & 0 deletions packages/environment-glimmerx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"description": "A Glint environment to support GlimmerX projects",
"license": "MIT",
"author": "Dan Freeman (https://github.com/dfreeman)",
"main": "-private/index.js",
"types": "-private/index.d.ts",
"glint-environment": "-private/environment/index.js",
"keywords": [
"glint-environment"
Expand Down
3 changes: 2 additions & 1 deletion test-packages/ts-ember-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"lint:hbs": "ember-template-lint .",
"lint:js": "eslint .",
"start": "ember serve",
"test": "npm-run-all typecheck test:browsers",
"test": "npm-run-all typecheck test:tsc test:browsers",
"typecheck": "glint",
"test:tsc": "tsc --noEmit",
"test:browsers": "ember test"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test-packages/ts-ember-app/types/demo-ember-app/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ember from 'ember';
import '@glint/environment-ember-loose/registry';
import '@glint/environment-ember-loose';

declare global {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down
3 changes: 2 additions & 1 deletion test-packages/ts-glimmerx-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"lint": "eslint . --cache",
"start": "webpack-dev-server",
"typecheck": "glint",
"test": "npm-run-all typecheck test:browsers",
"test": "npm-run-all typecheck test:tsc test:browsers",
"test:tsc": "tsc --noEmit",
"test:browsers": "testem ci",
"test:watch": "testem"
},
Expand Down
1 change: 1 addition & 0 deletions test-packages/ts-glimmerx-app/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@glint/environment-glimmerx';