From af9db198e574d316643d9cd0c7a13132d40133a2 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 12 Dec 2022 10:27:25 -0700 Subject: [PATCH] Introduce ambient type definitions 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]: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/63589 (cherry picked from commit 3907d48de6511cc89fcb4a650df68b65d3c1efa9) # Conflicts: # addon/package.json # package-lock.json # test-app/package.json --- index.d.ts | 2 ++ package.json | 1 + tests/dummy/app/app.js | 15 +++++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..b2fda688 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,2 @@ +import { Resolver as ResolverContract } from "@ember/owner"; +export default interface Resolver extends Required {} diff --git a/package.json b/package.json index 7f26b9f8..8f3779c2 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index 8df91db5..e8227003 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -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; @@ -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 + */