Skip to content

Commit

Permalink
Introduce ambient type definitions
Browse files Browse the repository at this point in the history
Ultimately we'd like to convert the package to TS, but this unblocks
wider ecosystem adoption of the stable/preview Ember types. This PR can
also serve as a model for other packages which want to publish types in
a similar way.

This will also work just fine with the `@types` packages from
DefinitelyTyped once [a key PR][pr] lands there, but that is not the
path we will recommend, so this only includes the `ember-source` peer
dependency.

[pr]: DefinitelyTyped/DefinitelyTyped#63589

(cherry picked from commit 3907d48)

# Conflicts:
#	addon/package.json
#	package-lock.json
#	test-app/package.json
  • Loading branch information
chriskrycho committed Dec 20, 2022
1 parent e6e436b commit af9db19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { Resolver as ResolverContract } from "@ember/owner";
export default interface Resolver extends Required<ResolverContract> {}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"bugs": {
"url": "https://github.com/ember-cli/ember-resolver/issues"
},
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/ember-cli/ember-resolver.git"
Expand Down
15 changes: 11 additions & 4 deletions tests/dummy/app/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Application from '@ember/application';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';
import Application from "@ember/application";
import Resolver from "./resolver";
import loadInitializers from "ember-load-initializers";
import config from "./config/environment";

export default class App extends Application {
modulePrefix = config.modulePrefix;
Expand All @@ -10,3 +10,10 @@ export default class App extends Application {
}

loadInitializers(App, config.modulePrefix);

// Makes Ember's type definitions visible throughout the project, thereby using
// TS to power autocomplete for all Ember types in any editor.
/**
* @typedef {import('ember-source/types')} Stable
* @typedef {import('ember-source/types/preview')} Preview
*/

0 comments on commit af9db19

Please sign in to comment.