From 6278a8b7cfe55ef2b138ec7d1324bc5cc79544c3 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 22 Aug 2022 21:32:04 -0600 Subject: [PATCH 01/39] [FEATURE] Introduce a preview types package Copy the types from DefinitelyTyped, and set up a bare minimum config to make it possible to iterate on them. This particular commit fails all type checking and has an enormous amount of work to do, but provides a foundation on which we can iterate. --- .eslintrc.js | 21 + package.json | 5 + .../-private/event-dispatcher.d.ts | 16 + .../@ember/application/-private/registry.d.ts | 9 + .../@ember/application/deprecations.d.ts | 23 + types/preview/@ember/application/index.d.ts | 159 ++++++ .../preview/@ember/application/instance.d.ts | 7 + .../application/test/application-instance.ts | 44 ++ .../@ember/application/test/application.ts | 43 ++ .../@ember/application/test/deprecations.ts | 17 + .../preview/@ember/application/test/index.ts | 28 + .../preview/@ember/application/tsconfig.json | 3 + types/preview/@ember/application/types.d.ts | 27 + .../@ember/array/-private/enumerable.d.ts | 179 ++++++ .../array/-private/mutable-enumerable.d.ts | 28 + .../@ember/array/-private/native-array.d.ts | 23 + types/preview/@ember/array/index.d.ts | 79 +++ types/preview/@ember/array/mutable.d.ts | 75 +++ types/preview/@ember/array/proxy.d.ts | 31 ++ types/preview/@ember/array/test/array-ext.ts | 23 + .../preview/@ember/array/test/array-proxy.ts | 57 ++ types/preview/@ember/array/test/array.ts | 65 +++ types/preview/@ember/array/test/lib/assert.ts | 2 + types/preview/@ember/array/tsconfig.json | 3 + .../array/types/prototype-extensions.d.ts | 5 + .../-private/class-names-support.d.ts | 25 + .../@ember/component/-private/core-view.d.ts | 12 + .../-private/glimmer-interfaces.d.ts | 44 ++ .../@ember/component/-private/view-mixin.d.ts | 57 ++ types/preview/@ember/component/helper.d.ts | 198 +++++++ types/preview/@ember/component/index.d.ts | 131 +++++ .../@ember/component/template-only.d.ts | 46 ++ .../@ember/component/test/built-ins.ts | 4 + .../@ember/component/test/component.ts | 157 ++++++ types/preview/@ember/component/test/helper.ts | 128 +++++ .../@ember/component/test/lib/assert.ts | 2 + .../@ember/component/test/template-only.ts | 28 + types/preview/@ember/component/tsconfig.json | 3 + types/preview/@ember/controller/index.d.ts | 47 ++ types/preview/@ember/controller/test/main.ts | 14 + .../preview/@ember/controller/test/octane.ts | 36 ++ types/preview/@ember/controller/tsconfig.json | 3 + .../@ember/debug/container-debug-adapter.d.ts | 11 + types/preview/@ember/debug/data-adapter.d.ts | 62 +++ .../@ember/debug/ember__debug-tests.ts | 237 ++++++++ types/preview/@ember/debug/index.d.ts | 100 ++++ types/preview/@ember/debug/tsconfig.json | 3 + types/preview/@ember/destroyable/index.d.ts | 29 + .../@ember/destroyable/test/lib/assert.ts | 2 + types/preview/@ember/destroyable/test/main.ts | 91 +++ .../preview/@ember/destroyable/tsconfig.json | 3 + .../-private/container-proxy-mixin.d.ts | 15 + .../engine/-private/registry-proxy-mixin.d.ts | 52 ++ .../engine/-private/types/initializer.d.ts | 6 + types/preview/@ember/engine/index.d.ts | 65 +++ types/preview/@ember/engine/instance.d.ts | 22 + .../@ember/engine/test/engine-instance.ts | 26 + types/preview/@ember/engine/test/engine.ts | 43 ++ types/preview/@ember/engine/tsconfig.json | 3 + .../@ember/error/ember__error-tests.ts | 7 + types/preview/@ember/error/index.d.ts | 12 + types/preview/@ember/error/tsconfig.json | 3 + .../@ember/helper/ember__helper-tests.ts | 7 + types/preview/@ember/helper/index.d.ts | 55 ++ types/preview/@ember/helper/tsconfig.json | 3 + .../@ember/modifier/ember__modifier-tests.ts | 8 + types/preview/@ember/modifier/index.d.ts | 39 ++ types/preview/@ember/modifier/tsconfig.json | 3 + .../object/-private/action-handler.d.ts | 28 + .../preview/@ember/object/-private/types.d.ts | 61 ++ types/preview/@ember/object/compat.d.ts | 7 + types/preview/@ember/object/computed.d.ts | 261 +++++++++ types/preview/@ember/object/core.d.ts | 82 +++ types/preview/@ember/object/evented.d.ts | 60 ++ types/preview/@ember/object/events.d.ts | 49 ++ types/preview/@ember/object/index.d.ts | 116 ++++ types/preview/@ember/object/internals.d.ts | 15 + types/preview/@ember/object/mixin.d.ts | 17 + types/preview/@ember/object/observable.d.ts | 78 +++ types/preview/@ember/object/observers.d.ts | 32 ++ .../@ember/object/promise-proxy-mixin.d.ts | 35 ++ types/preview/@ember/object/proxy.d.ts | 25 + .../@ember/object/test/access-modifier.ts | 29 + types/preview/@ember/object/test/compat.ts | 12 + types/preview/@ember/object/test/computed.ts | 231 ++++++++ types/preview/@ember/object/test/core.ts | 218 ++++++++ .../@ember/object/test/create-negative.ts | 11 + types/preview/@ember/object/test/create.ts | 54 ++ types/preview/@ember/object/test/event.ts | 92 +++ types/preview/@ember/object/test/extend.ts | 61 ++ types/preview/@ember/object/test/get-set.ts | 14 + types/preview/@ember/object/test/internals.ts | 10 + .../preview/@ember/object/test/lib/assert.ts | 2 + types/preview/@ember/object/test/object.ts | 102 ++++ .../preview/@ember/object/test/observable.ts | 102 ++++ types/preview/@ember/object/test/octane.ts | 331 +++++++++++ types/preview/@ember/object/test/proxy.ts | 103 ++++ types/preview/@ember/object/test/reopen.ts | 75 +++ types/preview/@ember/object/tsconfig.json | 3 + .../@ember/owner/ember__owner-tests.ts | 135 +++++ types/preview/@ember/owner/index.d.ts | 104 ++++ types/preview/@ember/owner/tsconfig.json | 3 + .../polyfills/ember__polyfills-tests.ts | 23 + types/preview/@ember/polyfills/index.d.ts | 29 + types/preview/@ember/polyfills/tsconfig.json | 3 + types/preview/@ember/polyfills/types.d.ts | 4 + .../-private/route-info-with-attributes.d.ts | 1 + .../@ember/routing/-private/route-info.d.ts | 1 + .../@ember/routing/-private/router-dsl.d.ts | 18 + .../@ember/routing/-private/transition.d.ts | 1 + .../preview/@ember/routing/auto-location.d.ts | 6 + .../preview/@ember/routing/hash-location.d.ts | 8 + .../@ember/routing/history-location.d.ts | 7 + types/preview/@ember/routing/index.d.ts | 26 + .../preview/@ember/routing/none-location.d.ts | 9 + types/preview/@ember/routing/route-info.d.ts | 72 +++ types/preview/@ember/routing/route.d.ts | 525 ++++++++++++++++++ .../@ember/routing/router-service.d.ts | 360 ++++++++++++ types/preview/@ember/routing/router.d.ts | 43 ++ .../preview/@ember/routing/test/built-ins.ts | 3 + .../preview/@ember/routing/test/lib/assert.ts | 2 + types/preview/@ember/routing/test/route.ts | 227 ++++++++ .../@ember/routing/test/router-service.ts | 120 ++++ types/preview/@ember/routing/test/router.ts | 81 +++ types/preview/@ember/routing/transition.d.ts | 124 +++++ types/preview/@ember/routing/tsconfig.json | 3 + types/preview/@ember/routing/types.d.ts | 13 + .../@ember/runloop/-private/backburner.d.ts | 41 ++ .../@ember/runloop/-private/types.d.ts | 1 + .../@ember/runloop/ember__runloop-tests.ts | 279 ++++++++++ types/preview/@ember/runloop/index.d.ts | 179 ++++++ types/preview/@ember/runloop/tsconfig.json | 3 + types/preview/@ember/runloop/types.d.ts | 3 + types/preview/@ember/service/index.d.ts | 32 ++ types/preview/@ember/service/test/main.ts | 58 ++ types/preview/@ember/service/test/octane.ts | 34 ++ types/preview/@ember/service/tsconfig.json | 3 + .../@ember/template/-private/handlebars.d.ts | 5 + .../@ember/template/ember__template-tests.ts | 15 + types/preview/@ember/template/index.d.ts | 11 + types/preview/@ember/template/tsconfig.json | 3 + types/preview/@ember/test/adapter.d.ts | 20 + .../preview/@ember/test/ember__test-tests.ts | 42 ++ types/preview/@ember/test/index.d.ts | 55 ++ types/preview/@ember/test/tsconfig.json | 3 + .../preview/@ember/utils/-private/types.d.ts | 36 ++ .../@ember/utils/ember__utils-tests.ts | 145 +++++ types/preview/@ember/utils/index.d.ts | 49 ++ types/preview/@ember/utils/tsconfig.json | 3 + types/preview/ember/-private/type-utils.d.ts | 52 ++ types/preview/ember/index.d.ts | 401 +++++++++++++ types/preview/ember/test/access-modifier.ts | 42 ++ .../ember/test/application-instance.ts | 29 + types/preview/ember/test/application.ts | 43 ++ types/preview/ember/test/array-ext.ts | 21 + types/preview/ember/test/array-proxy.ts | 26 + types/preview/ember/test/array.ts | 50 ++ types/preview/ember/test/component.ts | 124 +++++ types/preview/ember/test/computed.ts | 192 +++++++ types/preview/ember/test/controller.ts | 11 + types/preview/ember/test/core-object.ts | 218 ++++++++ types/preview/ember/test/create-negative.ts | 14 + types/preview/ember/test/create.ts | 55 ++ types/preview/ember/test/data-adapter.ts | 59 ++ types/preview/ember/test/debug.ts | 99 ++++ .../preview/ember/test/ember-module-tests.ts | 295 ++++++++++ types/preview/ember/test/ember-tests.ts | 190 +++++++ types/preview/ember/test/engine-instance.ts | 27 + types/preview/ember/test/engine.ts | 43 ++ types/preview/ember/test/error.ts | 5 + types/preview/ember/test/event.ts | 60 ++ types/preview/ember/test/extend.ts | 61 ++ types/preview/ember/test/helper.ts | 45 ++ types/preview/ember/test/inject.ts | 60 ++ types/preview/ember/test/lib/assert.ts | 2 + types/preview/ember/test/mixin.ts | 57 ++ types/preview/ember/test/object.ts | 84 +++ types/preview/ember/test/observable.ts | 116 ++++ .../ember/test/private/computed-tests.ts | 92 +++ .../ember/test/private/observable-tests.ts | 200 +++++++ types/preview/ember/test/reopen.ts | 64 +++ types/preview/ember/test/route.ts | 97 ++++ types/preview/ember/test/router.ts | 49 ++ types/preview/ember/test/run.ts | 220 ++++++++ types/preview/ember/test/string.ts | 51 ++ .../test/techniques/properties-from-this.ts | 71 +++ types/preview/ember/test/test.ts | 32 ++ types/preview/ember/test/transition.ts | 29 + types/preview/ember/test/utils.ts | 146 +++++ types/preview/ember/test/view-utils.ts | 7 + types/preview/ember/tsconfig.json | 3 + types/preview/tsconfig.json | 6 + yarn.lock | 339 ++++++++++- 193 files changed, 11981 insertions(+), 7 deletions(-) create mode 100644 types/preview/@ember/application/-private/event-dispatcher.d.ts create mode 100644 types/preview/@ember/application/-private/registry.d.ts create mode 100644 types/preview/@ember/application/deprecations.d.ts create mode 100644 types/preview/@ember/application/index.d.ts create mode 100644 types/preview/@ember/application/instance.d.ts create mode 100644 types/preview/@ember/application/test/application-instance.ts create mode 100755 types/preview/@ember/application/test/application.ts create mode 100644 types/preview/@ember/application/test/deprecations.ts create mode 100644 types/preview/@ember/application/test/index.ts create mode 100644 types/preview/@ember/application/tsconfig.json create mode 100644 types/preview/@ember/application/types.d.ts create mode 100644 types/preview/@ember/array/-private/enumerable.d.ts create mode 100644 types/preview/@ember/array/-private/mutable-enumerable.d.ts create mode 100644 types/preview/@ember/array/-private/native-array.d.ts create mode 100644 types/preview/@ember/array/index.d.ts create mode 100644 types/preview/@ember/array/mutable.d.ts create mode 100644 types/preview/@ember/array/proxy.d.ts create mode 100755 types/preview/@ember/array/test/array-ext.ts create mode 100644 types/preview/@ember/array/test/array-proxy.ts create mode 100755 types/preview/@ember/array/test/array.ts create mode 100755 types/preview/@ember/array/test/lib/assert.ts create mode 100644 types/preview/@ember/array/tsconfig.json create mode 100644 types/preview/@ember/array/types/prototype-extensions.d.ts create mode 100644 types/preview/@ember/component/-private/class-names-support.d.ts create mode 100644 types/preview/@ember/component/-private/core-view.d.ts create mode 100644 types/preview/@ember/component/-private/glimmer-interfaces.d.ts create mode 100644 types/preview/@ember/component/-private/view-mixin.d.ts create mode 100644 types/preview/@ember/component/helper.d.ts create mode 100644 types/preview/@ember/component/index.d.ts create mode 100644 types/preview/@ember/component/template-only.d.ts create mode 100644 types/preview/@ember/component/test/built-ins.ts create mode 100644 types/preview/@ember/component/test/component.ts create mode 100644 types/preview/@ember/component/test/helper.ts create mode 100755 types/preview/@ember/component/test/lib/assert.ts create mode 100644 types/preview/@ember/component/test/template-only.ts create mode 100644 types/preview/@ember/component/tsconfig.json create mode 100644 types/preview/@ember/controller/index.d.ts create mode 100644 types/preview/@ember/controller/test/main.ts create mode 100644 types/preview/@ember/controller/test/octane.ts create mode 100644 types/preview/@ember/controller/tsconfig.json create mode 100644 types/preview/@ember/debug/container-debug-adapter.d.ts create mode 100644 types/preview/@ember/debug/data-adapter.d.ts create mode 100644 types/preview/@ember/debug/ember__debug-tests.ts create mode 100644 types/preview/@ember/debug/index.d.ts create mode 100644 types/preview/@ember/debug/tsconfig.json create mode 100644 types/preview/@ember/destroyable/index.d.ts create mode 100644 types/preview/@ember/destroyable/test/lib/assert.ts create mode 100644 types/preview/@ember/destroyable/test/main.ts create mode 100644 types/preview/@ember/destroyable/tsconfig.json create mode 100644 types/preview/@ember/engine/-private/container-proxy-mixin.d.ts create mode 100644 types/preview/@ember/engine/-private/registry-proxy-mixin.d.ts create mode 100644 types/preview/@ember/engine/-private/types/initializer.d.ts create mode 100644 types/preview/@ember/engine/index.d.ts create mode 100644 types/preview/@ember/engine/instance.d.ts create mode 100644 types/preview/@ember/engine/test/engine-instance.ts create mode 100755 types/preview/@ember/engine/test/engine.ts create mode 100644 types/preview/@ember/engine/tsconfig.json create mode 100644 types/preview/@ember/error/ember__error-tests.ts create mode 100644 types/preview/@ember/error/index.d.ts create mode 100644 types/preview/@ember/error/tsconfig.json create mode 100644 types/preview/@ember/helper/ember__helper-tests.ts create mode 100644 types/preview/@ember/helper/index.d.ts create mode 100644 types/preview/@ember/helper/tsconfig.json create mode 100644 types/preview/@ember/modifier/ember__modifier-tests.ts create mode 100644 types/preview/@ember/modifier/index.d.ts create mode 100644 types/preview/@ember/modifier/tsconfig.json create mode 100644 types/preview/@ember/object/-private/action-handler.d.ts create mode 100644 types/preview/@ember/object/-private/types.d.ts create mode 100644 types/preview/@ember/object/compat.d.ts create mode 100644 types/preview/@ember/object/computed.d.ts create mode 100644 types/preview/@ember/object/core.d.ts create mode 100644 types/preview/@ember/object/evented.d.ts create mode 100644 types/preview/@ember/object/events.d.ts create mode 100644 types/preview/@ember/object/index.d.ts create mode 100644 types/preview/@ember/object/internals.d.ts create mode 100644 types/preview/@ember/object/mixin.d.ts create mode 100644 types/preview/@ember/object/observable.d.ts create mode 100644 types/preview/@ember/object/observers.d.ts create mode 100644 types/preview/@ember/object/promise-proxy-mixin.d.ts create mode 100644 types/preview/@ember/object/proxy.d.ts create mode 100644 types/preview/@ember/object/test/access-modifier.ts create mode 100644 types/preview/@ember/object/test/compat.ts create mode 100644 types/preview/@ember/object/test/computed.ts create mode 100644 types/preview/@ember/object/test/core.ts create mode 100644 types/preview/@ember/object/test/create-negative.ts create mode 100644 types/preview/@ember/object/test/create.ts create mode 100644 types/preview/@ember/object/test/event.ts create mode 100644 types/preview/@ember/object/test/extend.ts create mode 100644 types/preview/@ember/object/test/get-set.ts create mode 100644 types/preview/@ember/object/test/internals.ts create mode 100644 types/preview/@ember/object/test/lib/assert.ts create mode 100644 types/preview/@ember/object/test/object.ts create mode 100644 types/preview/@ember/object/test/observable.ts create mode 100644 types/preview/@ember/object/test/octane.ts create mode 100644 types/preview/@ember/object/test/proxy.ts create mode 100644 types/preview/@ember/object/test/reopen.ts create mode 100644 types/preview/@ember/object/tsconfig.json create mode 100644 types/preview/@ember/owner/ember__owner-tests.ts create mode 100644 types/preview/@ember/owner/index.d.ts create mode 100644 types/preview/@ember/owner/tsconfig.json create mode 100644 types/preview/@ember/polyfills/ember__polyfills-tests.ts create mode 100644 types/preview/@ember/polyfills/index.d.ts create mode 100644 types/preview/@ember/polyfills/tsconfig.json create mode 100644 types/preview/@ember/polyfills/types.d.ts create mode 100644 types/preview/@ember/routing/-private/route-info-with-attributes.d.ts create mode 100644 types/preview/@ember/routing/-private/route-info.d.ts create mode 100644 types/preview/@ember/routing/-private/router-dsl.d.ts create mode 100644 types/preview/@ember/routing/-private/transition.d.ts create mode 100644 types/preview/@ember/routing/auto-location.d.ts create mode 100644 types/preview/@ember/routing/hash-location.d.ts create mode 100644 types/preview/@ember/routing/history-location.d.ts create mode 100644 types/preview/@ember/routing/index.d.ts create mode 100644 types/preview/@ember/routing/none-location.d.ts create mode 100644 types/preview/@ember/routing/route-info.d.ts create mode 100644 types/preview/@ember/routing/route.d.ts create mode 100644 types/preview/@ember/routing/router-service.d.ts create mode 100644 types/preview/@ember/routing/router.d.ts create mode 100644 types/preview/@ember/routing/test/built-ins.ts create mode 100755 types/preview/@ember/routing/test/lib/assert.ts create mode 100755 types/preview/@ember/routing/test/route.ts create mode 100644 types/preview/@ember/routing/test/router-service.ts create mode 100755 types/preview/@ember/routing/test/router.ts create mode 100644 types/preview/@ember/routing/transition.d.ts create mode 100644 types/preview/@ember/routing/tsconfig.json create mode 100644 types/preview/@ember/routing/types.d.ts create mode 100644 types/preview/@ember/runloop/-private/backburner.d.ts create mode 100644 types/preview/@ember/runloop/-private/types.d.ts create mode 100644 types/preview/@ember/runloop/ember__runloop-tests.ts create mode 100644 types/preview/@ember/runloop/index.d.ts create mode 100644 types/preview/@ember/runloop/tsconfig.json create mode 100644 types/preview/@ember/runloop/types.d.ts create mode 100644 types/preview/@ember/service/index.d.ts create mode 100644 types/preview/@ember/service/test/main.ts create mode 100644 types/preview/@ember/service/test/octane.ts create mode 100644 types/preview/@ember/service/tsconfig.json create mode 100644 types/preview/@ember/template/-private/handlebars.d.ts create mode 100644 types/preview/@ember/template/ember__template-tests.ts create mode 100644 types/preview/@ember/template/index.d.ts create mode 100644 types/preview/@ember/template/tsconfig.json create mode 100644 types/preview/@ember/test/adapter.d.ts create mode 100644 types/preview/@ember/test/ember__test-tests.ts create mode 100644 types/preview/@ember/test/index.d.ts create mode 100644 types/preview/@ember/test/tsconfig.json create mode 100644 types/preview/@ember/utils/-private/types.d.ts create mode 100644 types/preview/@ember/utils/ember__utils-tests.ts create mode 100644 types/preview/@ember/utils/index.d.ts create mode 100644 types/preview/@ember/utils/tsconfig.json create mode 100644 types/preview/ember/-private/type-utils.d.ts create mode 100755 types/preview/ember/index.d.ts create mode 100644 types/preview/ember/test/access-modifier.ts create mode 100644 types/preview/ember/test/application-instance.ts create mode 100755 types/preview/ember/test/application.ts create mode 100755 types/preview/ember/test/array-ext.ts create mode 100644 types/preview/ember/test/array-proxy.ts create mode 100755 types/preview/ember/test/array.ts create mode 100755 types/preview/ember/test/component.ts create mode 100755 types/preview/ember/test/computed.ts create mode 100755 types/preview/ember/test/controller.ts create mode 100644 types/preview/ember/test/core-object.ts create mode 100644 types/preview/ember/test/create-negative.ts create mode 100755 types/preview/ember/test/create.ts create mode 100644 types/preview/ember/test/data-adapter.ts create mode 100644 types/preview/ember/test/debug.ts create mode 100644 types/preview/ember/test/ember-module-tests.ts create mode 100755 types/preview/ember/test/ember-tests.ts create mode 100644 types/preview/ember/test/engine-instance.ts create mode 100755 types/preview/ember/test/engine.ts create mode 100644 types/preview/ember/test/error.ts create mode 100755 types/preview/ember/test/event.ts create mode 100755 types/preview/ember/test/extend.ts create mode 100755 types/preview/ember/test/helper.ts create mode 100755 types/preview/ember/test/inject.ts create mode 100755 types/preview/ember/test/lib/assert.ts create mode 100755 types/preview/ember/test/mixin.ts create mode 100755 types/preview/ember/test/object.ts create mode 100755 types/preview/ember/test/observable.ts create mode 100644 types/preview/ember/test/private/computed-tests.ts create mode 100644 types/preview/ember/test/private/observable-tests.ts create mode 100755 types/preview/ember/test/reopen.ts create mode 100755 types/preview/ember/test/route.ts create mode 100755 types/preview/ember/test/router.ts create mode 100755 types/preview/ember/test/run.ts create mode 100644 types/preview/ember/test/string.ts create mode 100644 types/preview/ember/test/techniques/properties-from-this.ts create mode 100755 types/preview/ember/test/test.ts create mode 100755 types/preview/ember/test/transition.ts create mode 100755 types/preview/ember/test/utils.ts create mode 100644 types/preview/ember/test/view-utils.ts create mode 100755 types/preview/ember/tsconfig.json create mode 100644 types/preview/tsconfig.json diff --git a/.eslintrc.js b/.eslintrc.js index 921dc164dd6..07cabcb5d36 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -65,6 +65,27 @@ module.exports = { 'prefer-rest-params': 'off', }, }, + { + files: ['types/preview/**/*.ts'], + + extends: ['plugin:@typescript-eslint/recommended'], + + parserOptions: { + sourceType: 'module', + project: './types/preview/tsconfig.json', + tsconfigRootDir: __dirname, + }, + + rules: { + 'import/export': 'off', + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-empty-interface': 'off', + 'import/no-unresolved': 'off', + '@typescript-eslint/no-this-alias': 'off', + '@typescript-eslint/consistent-type-imports': 'error', + '@typescript-eslint/no-empty-function': 'off', + }, + }, { // TODO: files: ['packages/**/*.[jt]s'], files: ['packages/**/*.js'], diff --git a/package.json b/package.json index af8309ccb97..21640d79066 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "devDependencies": { "@babel/preset-env": "^7.16.11", "@glimmer/compiler": "0.84.2", + "@glimmer/component": "^1.1.2", "@glimmer/destroyable": "0.84.2", "@glimmer/env": "^0.1.7", "@glimmer/global-context": "0.84.2", @@ -93,6 +94,7 @@ "@glimmer/runtime": "0.84.2", "@glimmer/validator": "0.84.2", "@simple-dom/document": "^1.4.0", + "@tsconfig/ember": "^1.0.1", "@types/qunit": "^2.19.2", "@types/rsvp": "^4.0.4", "@typescript-eslint/eslint-plugin": "^5.22.0", @@ -154,6 +156,9 @@ "testem-failure-only-reporter": "^1.0.0", "typescript": "~4.6.4" }, + "peerDependencies": { + "@glimmer/component": "^1.1.2" + }, "engines": { "node": ">= 12.*" }, diff --git a/types/preview/@ember/application/-private/event-dispatcher.d.ts b/types/preview/@ember/application/-private/event-dispatcher.d.ts new file mode 100644 index 00000000000..3df6d612ad7 --- /dev/null +++ b/types/preview/@ember/application/-private/event-dispatcher.d.ts @@ -0,0 +1,16 @@ +import { EventDispatcherEvents } from '@ember/application/types'; + +/** + * `Ember.EventDispatcher` handles delegating browser events to their + * corresponding `Ember.Views.` For example, when you click on a view, + * `Ember.EventDispatcher` ensures that that view's `mouseDown` method gets + * called. + */ +export default class EventDispatcher extends Object { + /** + * The set of events names (and associated handler function names) to be setup + * and dispatched by the `EventDispatcher`. Modifications to this list can be done + * at setup time, generally via the `Ember.Application.customEvents` hash. + */ + events: EventDispatcherEvents; +} diff --git a/types/preview/@ember/application/-private/registry.d.ts b/types/preview/@ember/application/-private/registry.d.ts new file mode 100644 index 00000000000..dc5ca32d531 --- /dev/null +++ b/types/preview/@ember/application/-private/registry.d.ts @@ -0,0 +1,9 @@ +import { EmberClassConstructor } from '@ember/object/-private/types'; + +/** + * A registry used to store factory and option information keyed + * by type. + */ +export default class Registry { + register(fullName: string, factory: EmberClassConstructor, options?: { singleton?: boolean | undefined }): void; +} diff --git a/types/preview/@ember/application/deprecations.d.ts b/types/preview/@ember/application/deprecations.d.ts new file mode 100644 index 00000000000..0ed913f11b6 --- /dev/null +++ b/types/preview/@ember/application/deprecations.d.ts @@ -0,0 +1,23 @@ +import { AnyFn } from 'ember/-private/type-utils'; + +// tslint:disable-next-line:strict-export-declare-modifiers +interface DeprecationOptions { + id: string; + until: string; + url?: string | undefined; +} + +/** + * Display a deprecation warning with the provided message and a stack trace + * (Chrome and Firefox only). + */ +export function deprecate(message: string, test: boolean, options: DeprecationOptions): void; + +/** + * Alias an old, deprecated method with its new counterpart. + */ +export function deprecateFunc( + message: string, + options: DeprecationOptions, + func: Func +): Func; diff --git a/types/preview/@ember/application/index.d.ts b/types/preview/@ember/application/index.d.ts new file mode 100644 index 00000000000..16b359ce356 --- /dev/null +++ b/types/preview/@ember/application/index.d.ts @@ -0,0 +1,159 @@ +// Type definitions for non-npm package @ember/application 4.0 +// Project: https://emberjs.com/api/ember/4.0/modules/@ember%2Fapplication +// Definitions by: Chris Krycho +// Dan Freeman +// James C. Davis +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Minimum TypeScript Version: 4.4 + +import Engine from '@ember/engine'; +import ApplicationInstance from '@ember/application/instance'; +import EventDispatcher from '@ember/application/-private/event-dispatcher'; +import { EventDispatcherEvents } from '@ember/application/types'; +import { Router } from '@ember/routing'; +import Registry from '@ember/application/-private/registry'; +import { Resolver } from '@ember/engine'; +import { AnyFn } from 'ember/-private/type-utils'; +import Owner from '@ember/owner'; +import type GlimmerComponent from '@glimmer/component'; +import EmberObject from '@ember/object'; + +// Shut off default exporting; we don't want anything but the *intended* +// public API present. +export {}; + +/** + * An instance of Ember.Application is the starting point for every Ember application. It helps to + * instantiate, initialize and coordinate the many objects that make up your app. + */ +export default class Application extends Engine { + /** + * Call advanceReadiness after any asynchronous setup logic has completed. + * Each call to deferReadiness must be matched by a call to advanceReadiness + * or the application will never become ready and routing will not begin. + */ + advanceReadiness(): void; + /** + * Use this to defer readiness until some condition is true. + * + * This allows you to perform asynchronous setup logic and defer + * booting your application until the setup has finished. + * + * However, if the setup requires a loading UI, it might be better + * to use the router for this purpose. + */ + deferReadiness(): void; + /** + * defines an injection or typeInjection + */ + inject(factoryNameOrType: string, property: string, injectionName: string): void; + /** + * This injects the test helpers into the window's scope. If a function of the + * same name has already been defined it will be cached (so that it can be reset + * if the helper is removed with `unregisterHelper` or `removeTestHelpers`). + * Any callbacks registered with `onInjectHelpers` will be called once the + * helpers have been injected. + */ + injectTestHelpers(): void; + /** + * registers a factory for later injection + * @param fullName type:name (e.g., 'model:user') + * @param factory (e.g., App.Person) + */ + register( + fullName: string, + factory: unknown, + options?: { singleton?: boolean | undefined; instantiate?: boolean | undefined } + ): void; + /** + * This removes all helpers that have been registered, and resets and functions + * that were overridden by the helpers. + */ + removeTestHelpers(): void; + /** + * Reset the application. This is typically used only in tests. + */ + reset(): void; + /** + * This hook defers the readiness of the application, so that you can start + * the app when your tests are ready to run. It also sets the router's + * location to 'none', so that the window's location will not be modified + * (preventing both accidental leaking of state between tests and interference + * with your testing framework). + */ + setupForTesting(): void; + /** + * The DOM events for which the event dispatcher should listen. + */ + customEvents: EventDispatcherEvents; + /** + * The Ember.EventDispatcher responsible for delegating events to this application's views. + */ + eventDispatcher: EventDispatcher; + /** + * Set this to provide an alternate class to `DefaultResolver` + */ + resolver: Resolver | null; + /** + * The root DOM element of the Application. This can be specified as an + * element or a jQuery-compatible selector string. + * + * This is the element that will be passed to the Application's, eventDispatcher, + * which sets up the listeners for event delegation. Every view in your application + * should be a child of the element you specify here. + */ + rootElement: HTMLElement | string; + /** + * Called when the Application has become ready. + * The call will be delayed until the DOM has become ready. + */ + ready: AnyFn; + /** + * Application's router. + */ + Router: Router; + registry: Registry; + /** + * Initialize the application and return a promise that resolves with the `Application` + * object when the boot process is complete. + */ + boot(): Promise; + /** + * Create an ApplicationInstance for this Application. + */ + buildInstance(options?: object): ApplicationInstance; +} + +// Known framework objects, so that `getOwner` can always, accurately, return +// `Owner` when working with one of these classes, which the framework *does* +// guarantee will always have an `Owner`. NOTE: this must be kept up to date +// whenever we add new base classes to the framework. For example, if we +// introduce a standalone `Service` or `Route` base class which *does not* +// extend from `EmberObject`, it will need to be added here. +type FrameworkObject = EmberObject | GlimmerComponent; + +/** + * Framework objects in an Ember application (components, services, routes, etc.) + * are created via a factory and dependency injection system. Each of these + * objects is the responsibility of an "owner", which handled its + * instantiation and manages its lifetime. + */ +export function getOwner(object: FrameworkObject): Owner; +export function getOwner(object: unknown): Owner | undefined; +/** + * `setOwner` forces a new owner on a given object instance. This is primarily + * useful in some testing cases. + */ +export function setOwner(object: unknown, owner: Owner): void; + +/** + * Detects when a specific package of Ember (e.g. 'Ember.Application') + * has fully loaded and is available for extension. + */ +export function onLoad(name: string, callback: AnyFn): unknown; + +/** + * Called when an Ember.js package (e.g Ember.Application) has finished + * loading. Triggers any callbacks registered for this event. + */ +export function runLoadHooks(name: string, object?: {}): unknown; diff --git a/types/preview/@ember/application/instance.d.ts b/types/preview/@ember/application/instance.d.ts new file mode 100644 index 00000000000..db5f37fcd5f --- /dev/null +++ b/types/preview/@ember/application/instance.d.ts @@ -0,0 +1,7 @@ +import EngineInstance from "@ember/engine/instance"; + +/** + * The `ApplicationInstance` encapsulates all of the stateful aspects of a + * running `Application`. + */ +export default class ApplicationInstance extends EngineInstance {} diff --git a/types/preview/@ember/application/test/application-instance.ts b/types/preview/@ember/application/test/application-instance.ts new file mode 100644 index 00000000000..32748ca0d96 --- /dev/null +++ b/types/preview/@ember/application/test/application-instance.ts @@ -0,0 +1,44 @@ +import ApplicationInstance from '@ember/application/instance'; +import hbs from 'htmlbars-inline-precompile'; + +const appInstance = ApplicationInstance.create(); +appInstance.register('some:injection', class Foo {}); + +appInstance.register('some:injection', class Foo {}, { + singleton: true, +}); + +appInstance.register('some:injection', class Foo {}, { + instantiate: false, +}); + +appInstance.register('templates:foo/bar', hbs`

Hello World

`); +appInstance.register('templates:foo/bar', hbs`

Hello World

`, { + singleton: true, +}); +appInstance.register('templates:foo/bar', hbs`

Hello World

`, { + instantiate: true, +}); +appInstance.register('templates:foo/bar', hbs`

Hello World

`, { + singleton: true, + instantiate: true, +}); +// @ts-expect-error +appInstance.register('templates:foo/bar', hbs`

Hello World

`, { + singleton: 'true', + instantiate: true, +}); + +appInstance.register('some:injection', class Foo {}, { + singleton: false, + instantiate: true, +}); + +appInstance.factoryFor('router:main'); +appInstance.lookup('route:basic'); + +appInstance.boot(); + +(async () => { + await appInstance.boot(); +})(); diff --git a/types/preview/@ember/application/test/application.ts b/types/preview/@ember/application/test/application.ts new file mode 100755 index 00000000000..8654afe83e4 --- /dev/null +++ b/types/preview/@ember/application/test/application.ts @@ -0,0 +1,43 @@ +import Application from '@ember/application'; +import EmberObject from '@ember/object'; + +const BaseApp = Application.extend({ + modulePrefix: 'my-app', +}); + +class Obj extends EmberObject.extend({ foo: 'bar' }) {} + +BaseApp.initializer({ + name: 'my-initializer', + initialize(app) { + app.register('foo:bar', Obj); + }, +}); + +BaseApp.instanceInitializer({ + name: 'my-instance-initializer', + initialize(app) { + (app.lookup('foo:bar') as Obj).get('foo'); + }, +}); + +const App1 = BaseApp.create({ + rootElement: '#app-one', + customEvents: { + paste: 'paste', + }, +}); + +const App2 = BaseApp.create({ + rootElement: '#app-two', + customEvents: { + mouseenter: null, + mouseleave: null, + }, +}); + +const App3 = BaseApp.create(); + +const App3Instance1 = App3.buildInstance(); // $ExpectType ApplicationInstance + +const App3Instance2 = App3.buildInstance({ foo: 'bar' }); // $ExpectType ApplicationInstance diff --git a/types/preview/@ember/application/test/deprecations.ts b/types/preview/@ember/application/test/deprecations.ts new file mode 100644 index 00000000000..e9bb19ed390 --- /dev/null +++ b/types/preview/@ember/application/test/deprecations.ts @@ -0,0 +1,17 @@ +import { deprecate, deprecateFunc } from '@ember/application/deprecations'; + +deprecate('this is no longer advised', false, { + id: 'no-longer-advised', + until: 'v4.0', +}); +deprecate('this is no longer advised', false, { + id: 'no-longer-advised', + until: 'v4.0', + url: 'https://emberjs.com', +}); +// @ts-expect-error +deprecate('this is no longer advised', false); + +// @ts-expect-error +deprecateFunc('this is no longer advised', () => {}); +deprecateFunc('this is no longer advised', { id: 'no-longer-do-this', until: 'v4.0' }, () => {}); diff --git a/types/preview/@ember/application/test/index.ts b/types/preview/@ember/application/test/index.ts new file mode 100644 index 00000000000..521a4b6936d --- /dev/null +++ b/types/preview/@ember/application/test/index.ts @@ -0,0 +1,28 @@ +import { getOwner, setOwner } from '@ember/application'; +import EngineInstance from '@ember/engine/instance'; +import Owner from '@ember/owner'; +import ApplicationInstance from '@ember/application/instance'; +import Service from '@ember/service'; + +// $ExpectType Owner | undefined +getOwner({}); + +// Confirm that random subclasses work as expected. +declare class MyService extends Service { + withStuff: true; +} +declare let myService: MyService; +// $ExpectType Owner +getOwner(myService); + +// @ts-expect-error +getOwner(); + +declare let baseOwner: Owner; +setOwner({}, baseOwner); + +declare let engine: EngineInstance; +setOwner({}, engine); + +declare let application: ApplicationInstance; +setOwner({}, application); diff --git a/types/preview/@ember/application/tsconfig.json b/types/preview/@ember/application/tsconfig.json new file mode 100644 index 00000000000..4082f16a5d9 --- /dev/null +++ b/types/preview/@ember/application/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.json" +} diff --git a/types/preview/@ember/application/types.d.ts b/types/preview/@ember/application/types.d.ts new file mode 100644 index 00000000000..f03863c4d29 --- /dev/null +++ b/types/preview/@ember/application/types.d.ts @@ -0,0 +1,27 @@ +export interface EventDispatcherEvents { + touchstart?: string | null | undefined; + touchmove?: string | null | undefined; + touchend?: string | null | undefined; + touchcancel?: string | null | undefined; + keydown?: string | null | undefined; + keyup?: string | null | undefined; + keypress?: string | null | undefined; + mousedown?: string | null | undefined; + mouseup?: string | null | undefined; + contextmenu?: string | null | undefined; + click?: string | null | undefined; + dblclick?: string | null | undefined; + focusin?: string | null | undefined; + focusout?: string | null | undefined; + submit?: string | null | undefined; + input?: string | null | undefined; + change?: string | null | undefined; + dragstart?: string | null | undefined; + drag?: string | null | undefined; + dragenter?: string | null | undefined; + dragleave?: string | null | undefined; + dragover?: string | null | undefined; + drop?: string | null | undefined; + dragend?: string | null | undefined; + [event: string]: string | null | undefined; +} diff --git a/types/preview/@ember/array/-private/enumerable.d.ts b/types/preview/@ember/array/-private/enumerable.d.ts new file mode 100644 index 00000000000..ca22d5a29fc --- /dev/null +++ b/types/preview/@ember/array/-private/enumerable.d.ts @@ -0,0 +1,179 @@ +import ComputedProperty from '@ember/object/computed'; +import Mixin from '@ember/object/mixin'; +import NativeArray from '@ember/array/-private/native-array'; +import EmberArray from '@ember/array'; +import { + AnyFn, + MethodNamesOf, + MethodParams, + MethodReturns, + MethodsOf, +} from 'ember/-private/type-utils'; + +/** + * This mixin defines the common interface implemented by enumerable objects + * in Ember. Most of these methods follow the standard Array iteration + * API defined up to JavaScript 1.8 (excluding language-specific features that + * cannot be emulated in older versions of JavaScript). + */ +interface Enumerable { + /** + * Helper method returns the first object from a collection. This is usually + * used by bindings and other parts of the framework to extract a single + * object if the enumerable contains only one item. + */ + firstObject: T | undefined; + /** + * Helper method returns the last object from a collection. If your enumerable + * contains only one object, this method should always return that object. + * If your enumerable is empty, this method should return `undefined`. + */ + lastObject: T | undefined; + /** + * Iterates through the enumerable, calling the passed function on each + * item. This method corresponds to the `forEach()` method defined in + * JavaScript 1.6. + */ + forEach: T[]['forEach']; + /** + * Alias for `mapBy` + */ + getEach(key: K): Array; + /** + * Sets the value on the named property for each member. This is more + * ergonomic than using other methods defined on this helper. If the object + * implements Ember.Observable, the value will be changed to `set(),` otherwise + * it will be set directly. `null` objects are skipped. + */ + setEach(key: K, value: T[K]): void; + /** + * Maps all of the items in the enumeration to another value, returning + * a new array. This method corresponds to `map()` defined in JavaScript 1.6. + */ + map: T[]['map']; + /** + * Similar to map, this specialized function returns the value of the named + * property on all items in the enumeration. + */ + mapBy(key: K): Array; + mapBy(key: string): unknown[]; + /** + * Returns an array with all of the items in the enumeration that the passed + * function returns true for. This method corresponds to `filter()` defined in + * JavaScript 1.6. + */ + filter: T[]['filter']; + /** + * Returns an array with all of the items in the enumeration where the passed + * function returns false. This method is the inverse of filter(). + */ + reject( + callbackfn: (value: T, index: number, array: T[]) => unknown, + thisArg?: any + ): NativeArray; + /** + * Returns an array with just the items with the matched property. You + * can pass an optional second argument with the target value. Otherwise + * this will match any property that evaluates to `true`. + */ + filterBy(key: K, value?: T[K]): NativeArray; + /** + * Returns an array with the items that do not have truthy values for + * key. You can pass an optional second argument with the target value. Otherwise + * this will match any property that evaluates to false. + */ + rejectBy(key: K, value?: T[K]): NativeArray; + /** + * Returns the first item in the array for which the callback returns true. + * This method works similar to the `filter()` method defined in JavaScript 1.6 + * except that it will stop working on the array once a match is found. + */ + find: T[]['find']; + /** + * Returns the first item with a property matching the passed value. You + * can pass an optional second argument with the target value. Otherwise + * this will match any property that evaluates to `true`. + */ + findBy(key: K, value?: T[K]): T | undefined; + /** + * Returns `true` if the passed function returns true for every item in the + * enumeration. This corresponds with the `every()` method in JavaScript 1.6. + */ + every: T[]['every']; + /** + * Returns `true` if the passed property resolves to the value of the second + * argument for all items in the enumerable. This method is often simpler/faster + * than using a callback. + */ + isEvery(key: K, value?: T[K]): boolean; + /** + * Returns `true` if the passed function returns true for any item in the + * enumeration. + */ + any(callback: (value: T, index: number, array: T[]) => boolean, target?: {}): boolean; + /** + * Returns `true` if the passed property resolves to the value of the second + * argument for any item in the enumerable. This method is often simpler/faster + * than using a callback. + */ + isAny(key: K, value?: T[K]): boolean; + /** + * This will combine the values of the enumerator into a single value. It + * is a useful way to collect a summary value from an enumeration. This + * corresponds to the `reduce()` method defined in JavaScript 1.8. + */ + reduce: T[]['reduce']; + /** + * Invokes the named method on every object in the receiver that + * implements it. This method corresponds to the implementation in + * Prototype 1.6. + */ + invoke>( + methodName: M, + ...args: MethodParams + ): Array>; + /** + * Simply converts the enumerable into a genuine array. The order is not + * guaranteed. Corresponds to the method implemented by Prototype. + */ + toArray(): T[]; + /** + * Returns a copy of the array with all `null` and `undefined` elements removed. + */ + compact(): NativeArray>; + /** + * Returns a new enumerable that excludes the passed value. The default + * implementation returns an array regardless of the receiver type. + * If the receiver does not contain the value it returns the original enumerable. + */ + without(value: T): NativeArray; + /** + * Returns a new enumerable that contains only unique values. The default + * implementation returns an array regardless of the receiver type. + */ + uniq(): NativeArray; + /** + * Converts the enumerable into an array and sorts by the keys + * specified in the argument. + */ + sortBy(...properties: string[]): NativeArray; + /** + * Returns a new enumerable that contains only items containing a unique property value. + * The default implementation returns an array regardless of the receiver type. + */ + uniqBy(property: string): NativeArray; + uniqBy(callback: (value: T) => unknown): NativeArray; + /** + * Returns `true` if the passed object can be found in the enumerable. + */ + includes(searchElement: T, fromIndex?: number): boolean; + /** + * This is the handler for the special array content property. If you get + * this property, it will return this. If you set this property to a new + * array, it will replace the current content. + */ + '[]': ComputedProperty; +} + +declare const Enumerable: Mixin>; +export default Enumerable; diff --git a/types/preview/@ember/array/-private/mutable-enumerable.d.ts b/types/preview/@ember/array/-private/mutable-enumerable.d.ts new file mode 100644 index 00000000000..c2786508b29 --- /dev/null +++ b/types/preview/@ember/array/-private/mutable-enumerable.d.ts @@ -0,0 +1,28 @@ +import Mixin from '@ember/object/mixin'; +import Enumerable from '@ember/array/-private/enumerable'; + +/** + * This mixin defines the API for modifying generic enumerables. These methods + * can be applied to an object regardless of whether it is ordered or + * unordered. + */ +interface MutableEnumerable extends Enumerable { + /** + * __Required.__ You must implement this method to apply this mixin. + */ + addObject(object: T): T; + /** + * Adds each object in the passed enumerable to the receiver. + */ + addObjects(objects: Enumerable): this; + /** + * __Required.__ You must implement this method to apply this mixin. + */ + removeObject(object: T): T; + /** + * Removes each object in the passed enumerable from the receiver. + */ + removeObjects(objects: Enumerable): this; +} +declare const MutableEnumerable: Mixin>; +export default MutableEnumerable; diff --git a/types/preview/@ember/array/-private/native-array.d.ts b/types/preview/@ember/array/-private/native-array.d.ts new file mode 100644 index 00000000000..c44ffbc1887 --- /dev/null +++ b/types/preview/@ember/array/-private/native-array.d.ts @@ -0,0 +1,23 @@ +import MutableArray from '@ember/array/mutable'; +import Observable from '@ember/object/observable'; +import Mixin from '@ember/object/mixin'; + +// Get an alias to the global Array type to use in inner scope below. +type GlobalArray = T[]; + +/** + * The NativeArray mixin contains the properties needed to make the native + * Array support Ember.MutableArray and all of its dependent APIs. Unless you + * have `EmberENV.EXTEND_PROTOTYPES` or `EmberENV.EXTEND_PROTOTYPES.Array` set to + * false, this will be applied automatically. Otherwise you can apply the mixin + * at anytime by calling `Ember.NativeArray.apply(Array.prototype)`. + */ +interface NativeArray extends GlobalArray, MutableArray, Observable { + /** + * __Required.__ You must implement this method to apply this mixin. + */ + length: number; +} + +declare const NativeArray: Mixin>; +export default NativeArray; diff --git a/types/preview/@ember/array/index.d.ts b/types/preview/@ember/array/index.d.ts new file mode 100644 index 00000000000..10b58c75dda --- /dev/null +++ b/types/preview/@ember/array/index.d.ts @@ -0,0 +1,79 @@ +// Type definitions for non-npm package @ember/array 4.0 +// Project: https://emberjs.com/api/ember/4.0/modules/@ember%2Farray +// Definitions by: Chris Krycho +// Dan Freeman +// James C. Davis +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Minimum TypeScript Version: 4.4 + +import ComputedProperty from "@ember/object/computed"; +import Mixin from "@ember/object/mixin"; +import Enumerable from "@ember/array/-private/enumerable"; +import NativeArray from "@ember/array/-private/native-array"; + +/** + * This module implements Observer-friendly Array-like behavior. This mixin is picked up by the + * Array class as well as other controllers, etc. that want to appear to be arrays. + */ +interface Array extends Enumerable { + /** + * __Required.__ You must implement this method to apply this mixin. + */ + length: number | ComputedProperty; + /** + * Returns the object at the given `index`. If the given `index` is negative + * or is greater or equal than the array length, returns `undefined`. + */ + objectAt(idx: number): T | undefined; + /** + * This returns the objects at the specified indexes, using `objectAt`. + */ + // tslint:disable-next-line:array-type + objectsAt(indexes: number[]): Array; + /** + * Returns a new array that is a slice of the receiver. This implementation + * uses the observable array methods to retrieve the objects for the new + * slice. + */ + slice(beginIndex?: number, endIndex?: number): T[]; + /** + * Returns the index of the given object's first occurrence. + * If no `startAt` argument is given, the starting location to + * search is 0. If it's negative, will count backward from + * the end of the array. Returns -1 if no match is found. + */ + indexOf(searchElement: T, fromIndex?: number): number; + /** + * Returns the index of the given object's last occurrence. + * If no `startAt` argument is given, the search starts from + * the last position. If it's negative, will count backward + * from the end of the array. Returns -1 if no match is found. + */ + lastIndexOf(searchElement: T, fromIndex?: number): number; + /** + * Returns a special object that can be used to observe individual properties + * on the array. Just get an equivalent property on this object and it will + * return an enumerable that maps automatically to the named key on the + * member objects. + */ + '@each': ComputedProperty; +} +// Ember.Array rather than Array because the `array-type` lint rule doesn't realize the global is shadowed +// tslint:disable-next-line:array-type +declare const Array: Mixin>; +export default Array; + +/** + * Creates an `Ember.NativeArray` from an Array like object. + * Does not modify the original object's contents. Ember.A is not needed if + * `EmberENV.EXTEND_PROTOTYPES` is `true` (the default value). However, + * it is recommended that you use Ember.A when creating addons for + * ember or when you can not guarantee that `EmberENV.EXTEND_PROTOTYPES` + * will be `true`. + */ +export function A(arr?: T[]): NativeArray; + +/** + * Returns true if the passed object is an array or Array-like. + */ +export function isArray(obj: unknown): obj is ArrayLike; diff --git a/types/preview/@ember/array/mutable.d.ts b/types/preview/@ember/array/mutable.d.ts new file mode 100644 index 00000000000..505408a66be --- /dev/null +++ b/types/preview/@ember/array/mutable.d.ts @@ -0,0 +1,75 @@ +import Mixin from "@ember/object/mixin"; +import MutableEnumerable from "@ember/array/-private/mutable-enumerable"; +import EmberArray from '@ember/array'; +import Enumerable from "@ember/array/-private/enumerable"; + +/** + * This mixin defines the API for modifying array-like objects. These methods + * can be applied only to a collection that keeps its items in an ordered set. + * It builds upon the Array mixin and adds methods to modify the array. + * One concrete implementations of this class include ArrayProxy. + */ +interface MutableArray extends EmberArray, MutableEnumerable { + /** + * __Required.__ You must implement this method to apply this mixin. + */ + replace(idx: number, amt: number, objects: T[]): this; + /** + * Remove all elements from the array. This is useful if you + * want to reuse an existing array without having to recreate it. + */ + clear(): this; + /** + * This will use the primitive `replace()` method to insert an object at the + * specified index. + */ + insertAt(idx: number, object: T): this; + /** + * Remove an object at the specified index using the `replace()` primitive + * method. You can pass either a single index, or a start and a length. + */ + removeAt(start: number, len?: number): this; + /** + * Push the object onto the end of the array. Works just like `push()` but it + * is KVO-compliant. + */ + pushObject(obj: T): T; + /** + * Add the objects in the passed numerable to the end of the array. Defers + * notifying observers of the change until all objects are added. + */ + pushObjects(objects: Enumerable): this; + /** + * Pop object from array or nil if none are left. Works just like `pop()` but + * it is KVO-compliant. + */ + popObject(): T; + /** + * Shift an object from start of array or nil if none are left. Works just + * like `shift()` but it is KVO-compliant. + */ + shiftObject(): T; + /** + * Unshift an object to start of array. Works just like `unshift()` but it is + * KVO-compliant. + */ + unshiftObject(obj: T): T; + /** + * Adds the named objects to the beginning of the array. Defers notifying + * observers until all objects have been added. + */ + unshiftObjects(objects: Enumerable): this; + /** + * Reverse objects in the array. Works just like `reverse()` but it is + * KVO-compliant. + */ + reverseObjects(): this; + /** + * Replace all the receiver's content with content of the argument. + * If argument is an empty array receiver will be cleared. + */ + setObjects(objects: EmberArray): this; +} + +declare const MutableArray: Mixin>; +export default MutableArray; diff --git a/types/preview/@ember/array/proxy.d.ts b/types/preview/@ember/array/proxy.d.ts new file mode 100644 index 00000000000..590f65fc2e7 --- /dev/null +++ b/types/preview/@ember/array/proxy.d.ts @@ -0,0 +1,31 @@ +import type MutableArray from '@ember/array/mutable'; +import EmberObject from '@ember/object'; + +interface EmberArrayLike { + length: number; + objectAt(idx: number): T | undefined; +} + +/** + * An ArrayProxy wraps any other object that is a native or Ember `Array` + * (checked with [`Ember.isArray`](https://api.emberjs.com/ember/release/functions/@ember%2Farray/isArray)), + * forwarding all requests. This makes it very useful for a number of + * binding use cases or other cases where being able to swap out the + * underlying array is useful. + * + * NOTE: Attempting to mutate the underlying content of an object that + * is not a `MutableArray` (e.g. a native Javascript Array) may not + * behave as expected. [`Ember.A`](https://api.emberjs.com/ember/release/functions/@ember%2Farray/A) + * may be used in this case. + */ +export default interface ArrayProxy extends MutableArray {} +export default class ArrayProxy extends EmberObject { + content: T[] | EmberArrayLike; + + /** + * Should actually retrieve the object at the specified index from the + * content. You can override this method in subclasses to transform the + * content item to something new. + */ + objectAtContent(idx: number): T | undefined; +} diff --git a/types/preview/@ember/array/test/array-ext.ts b/types/preview/@ember/array/test/array-ext.ts new file mode 100755 index 00000000000..d4fa40cf36c --- /dev/null +++ b/types/preview/@ember/array/test/array-ext.ts @@ -0,0 +1,23 @@ +import { assertType } from './lib/assert'; +import EmberObject from '@ember/object'; +import ArrayPrototypeExtensions from '@ember/array/types/prototype-extensions'; + +declare global { + interface Array extends ArrayPrototypeExtensions {} +} + +class Person extends EmberObject { + declare name: string; +} + +const person = Person.create({ name: 'Joe' }); +const array = [person]; + +assertType(array.get('length')); +assertType(array.get('firstObject')); +assertType(array.mapBy('name')); +assertType(array.map(p => p.get('name'))); +assertType(array.sortBy('name')); +assertType(array.uniq()); +assertType(array.uniqBy('name')); +assertType(array.uniqBy(p => p.get('name'))); diff --git a/types/preview/@ember/array/test/array-proxy.ts b/types/preview/@ember/array/test/array-proxy.ts new file mode 100644 index 00000000000..397f08183f7 --- /dev/null +++ b/types/preview/@ember/array/test/array-proxy.ts @@ -0,0 +1,57 @@ +import { assertType } from './lib/assert'; +import ArrayProxy from '@ember/array/proxy'; +import EmberArray, { A } from '@ember/array'; +import EmberObject from '@ember/object'; + +const pets = ['dog', 'cat', 'fish']; +const proxy = ArrayProxy.create({ content: A(pets) }); + +proxy.get('firstObject'); // 'dog' +proxy.set('content', A(['amoeba', 'paramecium'])); +proxy.get('firstObject'); // 'amoeba' + +const overridden = ArrayProxy.create({ + content: A(pets), + objectAtContent(idx: number): string | undefined { + return this.get('content').objectAt(idx)?.toUpperCase(); + }, +}); + +overridden.get('firstObject'); // 'DOG' + +class MyNewProxy extends ArrayProxy { + isNew = true; +} + +const x = MyNewProxy.create({ content: A([1, 2, 3]) }) as MyNewProxy; +assertType(x.get('firstObject')); +assertType(x.isNew); + +// Custom EmberArray +class MyArray extends EmberObject.extend(EmberArray) { + constructor(content: ArrayLike) { + super(); + this._content = content; + } + + _content: ArrayLike; + + get length() { + return this._content.length; + } + + objectAt(idx: number) { + return this._content[idx]; + } +} + +const customArrayProxy = ArrayProxy.create({ content: new MyArray(pets) }); +customArrayProxy.get('firstObject'); // 'dog' + +// Vanilla array +const vanillaArrayProxy = ArrayProxy.create({ content: pets }); +vanillaArrayProxy.get('firstObject'); // 'dog' + +// Nested ArrayProxy +const nestedArrayProxy = ArrayProxy.create({ content: proxy }); +nestedArrayProxy.get('firstObject'); // 'amoeba' diff --git a/types/preview/@ember/array/test/array.ts b/types/preview/@ember/array/test/array.ts new file mode 100755 index 00000000000..f035b6fdaa5 --- /dev/null +++ b/types/preview/@ember/array/test/array.ts @@ -0,0 +1,65 @@ +import { assertType } from './lib/assert'; +import EmberObject from '@ember/object'; +import EmberArray, { A } from '@ember/array'; +import MutableArray from '@ember/array/mutable'; + +type Person = typeof Person.prototype; +const Person = EmberObject.extend({ + name: '', + isHappy: false, +}); + +const people = A([Person.create({ name: 'Yehuda', isHappy: true }), Person.create({ name: 'Majd', isHappy: false })]); + +assertType(people.get('length')); +assertType(people.get('lastObject')); +assertType(people.get('firstObject')); +assertType(people.isAny('isHappy')); +assertType(people.isAny('isHappy', false)); +// @ts-expect-error +assertType(people.isAny('isHappy', "false")); + +assertType(people.objectAt(0)); +assertType>(people.objectsAt([1, 2, 3])); + +const persons1: Person[] = people.filterBy('isHappy'); +const persons2: MutableArray = people.filterBy('isHappy'); +const persons3: Person[] = people.rejectBy('isHappy'); +const persons4: MutableArray = people.rejectBy('isHappy'); +const persons5: Person[] = people.filter(person => person.get('name') === 'Yehuda'); +const persons6: MutableArray = people.filter(person => person.get('name') === 'Yehuda'); + +assertType(people.get('[]')); +assertType(people.get('[]').get('firstObject')); + +assertType(people.mapBy('isHappy')); +assertType(people.mapBy('name.length')); + +const last = people.get('lastObject'); // $ExpectType ({ name: string; isHappy: boolean; } & EmberObject & { name: string; isHappy: boolean; }) | undefined +if (last) { + assertType(last.get('name')); +} + +const first = people.get('lastObject'); +if (first) { + assertType(first.get('isHappy')); +} + +const letters: EmberArray = A(['a', 'b', 'c']); +const codes: number[] = letters.map((item, index, enumerable) => { + assertType(item); + assertType(index); + return item.charCodeAt(0); +}); + +const value = '1,2,3'; +const filters = A(value.split(',')); +filters.push('4'); +filters.sort(); + +const multiSortArr = A([ + { k: 'a', v: 'z' }, + { k: 'a', v: 'y' }, + { k: 'b', v: 'c' }, +]); +multiSortArr.sortBy('k', 'v'); diff --git a/types/preview/@ember/array/test/lib/assert.ts b/types/preview/@ember/array/test/lib/assert.ts new file mode 100755 index 00000000000..dad227ab5e9 --- /dev/null +++ b/types/preview/@ember/array/test/lib/assert.ts @@ -0,0 +1,2 @@ +/** Static assertion that `value` has type `T` */ +export declare function assertType(value: T): T; diff --git a/types/preview/@ember/array/tsconfig.json b/types/preview/@ember/array/tsconfig.json new file mode 100644 index 00000000000..4082f16a5d9 --- /dev/null +++ b/types/preview/@ember/array/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.json" +} diff --git a/types/preview/@ember/array/types/prototype-extensions.d.ts b/types/preview/@ember/array/types/prototype-extensions.d.ts new file mode 100644 index 00000000000..4609906857a --- /dev/null +++ b/types/preview/@ember/array/types/prototype-extensions.d.ts @@ -0,0 +1,5 @@ +// import Ember from 'ember'; +import Observable from '@ember/object/observable'; +import MutableArray from '@ember/array/mutable'; + +export default interface ArrayPrototypeExtensions extends MutableArray, Observable {} diff --git a/types/preview/@ember/component/-private/class-names-support.d.ts b/types/preview/@ember/component/-private/class-names-support.d.ts new file mode 100644 index 00000000000..59fabab2fda --- /dev/null +++ b/types/preview/@ember/component/-private/class-names-support.d.ts @@ -0,0 +1,25 @@ +import Mixin from '@ember/object/mixin'; + +interface ClassNamesSupport { + /** + * A list of properties of the view to apply as class names. If the property is a string value, + * the value of that string will be applied as a class name. + * + * If the value of the property is a Boolean, the name of that property is added as a dasherized + * class name. + * + * If you would prefer to use a custom value instead of the dasherized property name, you can + * pass a binding like this: `classNameBindings: ['isUrgent:urgent']` + * + * This list of properties is inherited from the component's superclasses as well. + */ + classNameBindings: string[]; + /** + * Standard CSS class names to apply to the view's outer element. This + * property automatically inherits any class names defined by the view's + * superclasses as well. + */ + classNames: string[]; +} +declare const ClassNamesSupport: Mixin; +export default ClassNamesSupport; diff --git a/types/preview/@ember/component/-private/core-view.d.ts b/types/preview/@ember/component/-private/core-view.d.ts new file mode 100644 index 00000000000..6a98d1716fb --- /dev/null +++ b/types/preview/@ember/component/-private/core-view.d.ts @@ -0,0 +1,12 @@ +import EmberObject from '@ember/object'; +import type Evented from '@ember/object/evented'; +import type ActionHandler from '@ember/object/-private/action-handler'; + +/** + * Ember.CoreView is an abstract class that exists to give view-like behavior to both Ember's main + * view class Ember.Component and other classes that don't need the full functionality of Ember.Component. + * + * Unless you have specific needs for CoreView, you will use Ember.Component in your applications. + */ +export default class CoreView extends EmberObject {} +export default interface CoreView extends Evented, ActionHandler {} diff --git a/types/preview/@ember/component/-private/glimmer-interfaces.d.ts b/types/preview/@ember/component/-private/glimmer-interfaces.d.ts new file mode 100644 index 00000000000..1b27d8f716f --- /dev/null +++ b/types/preview/@ember/component/-private/glimmer-interfaces.d.ts @@ -0,0 +1,44 @@ +// NOTE: this is a bare-minimum subset of the definitions of the types in +// `@glimmer/interfaces`, supplied to make the public types in this package +// accurate. + +// This is only present to "brand" the type, and it brands it in a way that +// matches [the implementation][1], which *also* uses it as a type-only brand. +// +// [1]: https://github.com/glimmerjs/glimmer-vm/blob/d6d776cf3797dafa923bcdad47e1897231ef6539/packages/%40glimmer/interfaces/lib/managers/capabilities.d.ts#L1 +// tslint:disable-next-line:strict-export-declare-modifiers +declare const CAPABILITIES: unique symbol; + +export interface Capabilities { + [CAPABILITIES]: true; +} + +export interface Arguments { + positional: readonly unknown[]; + named: Record; +} + +export interface ComponentCapabilitiesVersions { + '3.4': { + asyncLifecycleCallbacks?: boolean; + destructor?: boolean; + }; + + '3.13': { + asyncLifecycleCallbacks?: boolean; + destructor?: boolean; + updateHook?: boolean; + }; +} + +export interface ComponentCapabilities extends Capabilities { + asyncLifeCycleCallbacks: boolean; + destructor: boolean; + updateHook: boolean; +} + +export interface ComponentManager { + capabilities: ComponentCapabilities; + createComponent(factory: object, args: Arguments): ComponentStateBucket; + getContext(instance: ComponentStateBucket): unknown; +} diff --git a/types/preview/@ember/component/-private/view-mixin.d.ts b/types/preview/@ember/component/-private/view-mixin.d.ts new file mode 100644 index 00000000000..72b78927dad --- /dev/null +++ b/types/preview/@ember/component/-private/view-mixin.d.ts @@ -0,0 +1,57 @@ +import Mixin from '@ember/object/mixin'; + +interface ViewMixin { + /** + * A list of properties of the view to apply as attributes. If the property + * is a string value, the value of that string will be applied as the value + * for an attribute of the property's name. + */ + attributeBindings: string[]; + /** + * Returns the current DOM element for the view. + */ + element: Element; + /** + * The HTML `id` of the view's element in the DOM. You can provide this + * value yourself but it must be unique (just as in HTML): + */ + elementId: string; + /** + * Tag name for the view's outer element. The tag name is only used when an + * element is first created. If you change the `tagName` for an element, you + * must destroy and recreate the view element. + */ + tagName: string; + /** + * Renders the view again. This will work regardless of whether the + * view is already in the DOM or not. If the view is in the DOM, the + * rendering process will be deferred to give bindings a chance + * to synchronize. + */ + rerender(): void; + /** + * Called when a view is going to insert an element into the DOM. + */ + willInsertElement(): void; + /** + * Called when the element of the view has been inserted into the DOM. + * Override this function to do any set up that requires an element + * in the document body. + */ + didInsertElement(): void; + /** + * Called when the view is about to rerender, but before anything has + * been torn down. This is a good opportunity to tear down any manual + * observers you have installed based on the DOM state + */ + willClearRender(): void; + /** + * Called when the element of the view is going to be destroyed. Override + * this function to do any teardown that requires an element, like removing + * event listeners. + */ + willDestroyElement(): void; +} +declare const ViewMixin: Mixin; + +export default ViewMixin; diff --git a/types/preview/@ember/component/helper.d.ts b/types/preview/@ember/component/helper.d.ts new file mode 100644 index 00000000000..28a8cf37ec8 --- /dev/null +++ b/types/preview/@ember/component/helper.d.ts @@ -0,0 +1,198 @@ +import EmberObject from '@ember/object'; +import { Opaque } from 'ember/-private/type-utils'; + +// --- Type utilities for signatures --- // +// Type-only "symbol" to use with `EmptyObject` below, so that it is *not* +// equivalent to an empty interface. +declare const Empty: unique symbol; + +/** + * This provides us a way to have a "fallback" which represents an empty object, + * without the downsides of how TS treats `{}`. Specifically: this will + * correctly leverage "excess property checking" so that, given a component + * which has no named args, if someone invokes it with any named args, they will + * get a type error. + * + * @internal This is exported so declaration emit works (if it were not emitted, + * declarations which fall back to it would not work). It is *not* intended for + * public usage, and the specific mechanics it uses may change at any time. + * The location of this export *is* part of the public API, because moving it + * will break existing declarations, but is not legal for end users to import + * themselves, so ***DO NOT RELY ON IT***. + */ +export interface EmptyObject { + [Empty]?: true; +} + +type DefaultPositional = unknown[]; +type DefaultNamed = EmptyObject; + +/** + * The public shape of a helper. + * @deprecated Do not use this directly. Instead, write a `Signature` with the + * "normal" signature shape: `Args: { Named: { ... }, Positional: [...] }`. + */ +export interface HelperSignature { + NamedArgs?: DefaultNamed; + PositionalArgs?: DefaultPositional; + Return?: unknown; +} + +type GetOrElse = K extends keyof Obj ? Obj[K] : Fallback; + +/** Given a signature `S`, get back the `Args` type. */ +type ArgsFor = 'Args' extends keyof S + ? { + Named: GetOrElse; + Positional: GetOrElse; + } + : { Named: DefaultNamed; Positional: [] }; + +interface LegacyArgsFor { + Named: GetOrElse; + Positional: GetOrElse; +} + +// This type allows us to present a slightly-less-obtuse error message +// when attempting to resolve the signature of a helper that doesn't have +// one declared from within a tool like Glint. +declare const BadType: unique symbol; +interface BadType { + [BadType]: Message; +} + +interface MissingSignatureArgs { + Named: BadType<'This helper is missing a signature'>; + Positional: unknown[]; +} + +/** + * Given any allowed shorthand form of a signature, desugars it to its full + * expanded type. + * + * @internal This is only exported so we can avoid duplicating it in + * [Glint](https://github.com/typed-ember/glint) or other such tooling. It is + * *not* intended for public usage, and the specific mechanics it uses may + * change at any time. Although the signature produced by is part of Glimmer's + * public API the existence and mechanics of this specific symbol are *not*, + * so ***DO NOT RELY ON IT***. + */ +// This is similar but not identical to the `ExpandSignature` type used in the +// Glimmer Component API: it uses the same basic mechanics, but does not have +// an identical signature because we had not yet normalized the `Signature` when +// we designed the first pass of this. In the future, we will be able to make +// all `ExpandSignature` types fully general to work with *any* invokable. But +// "future" here probably means Ember v5. :sobbing: +export interface ExpandSignature { + Args: unknown extends T // Is this the default (i.e. unspecified) signature? + ? MissingSignatureArgs // Then return our special "missing signature" type + : keyof T extends 'Args' | 'Return' // Is this a `Signature`? + ? ArgsFor // Then use `Signature` args + : LegacyArgsFor; // Otherwise fall back to classic `Args`. + Return: 'Return' extends keyof T ? T['Return'] : unknown; +} + +// The `unknown extends S` checks on both of these are here to preserve backward +// compatibility with the existing non-`Signature` definition. When migrating +// into Ember or otherwise making a breaking change, we can drop the "default" +// in favor of just using `ExpandSignature`. +type NamedArgs = unknown extends S ? Record : ExpandSignature['Args']['Named']; +type PositionalArgs = unknown extends S ? unknown[] : ExpandSignature['Args']['Positional']; + +type Return = GetOrElse; + +/** + * Ember Helpers are functions that can compute values, and are used in templates. + * For example, this code calls a helper named `format-currency`: + */ +export default class Helper extends EmberObject { + /** + * In many cases, the ceremony of a full `Ember.Helper` class is not required. + * The `helper` method create pure-function helpers without instances. For + * example: + */ + static helper

( + helper: (positional: P, named: N) => R, + ): Helper<{ Args: { Positional: P; Named: N }; Return: R }>; + /** + * Override this function when writing a class-based helper. + */ + compute(positional: PositionalArgs, named: NamedArgs): Return; + /** + * On a class-based helper, it may be useful to force a recomputation of that + * helpers value. This is akin to `rerender` on a component. + */ + recompute(): void; +} + +// The generic here is for a *signature: a way to hang information for tools +// like Glint which can provide typey checking for component templates using +// information supplied via this generic. While it may appear useless on this +// class definition and extension, it is used by external tools and should not +// be removed. +// tslint:disable-next-line:no-unnecessary-generics +export default interface Helper extends Opaque {} + +// This type exists to provide a non-user-constructible, non-subclassable +// type representing the conceptual "instance type" of a function helper. +// The abstract field of type `never` presents subclassing in userspace of +// the value returned from `helper()`. By extending `Helper`, any +// augmentations of the `Helper` type performed by tools like Glint will +// also apply to function-based helpers as well. +export abstract class FunctionBasedHelperInstance extends Helper { + protected abstract __concrete__: never; +} + +/** + * The type of a function-based helper. + * + * @note This is *not* user-constructible: it is exported only so that the type + * returned by the `helper` function can be named (and indeed can be exported + * like `export default helper(...)` safely). + */ +// Making `FunctionBasedHelper` a bare constructor type allows for type +// parameters to be preserved when `helper()` is passed a generic function. +// By making it `abstract` and impossible to subclass (see above), we prevent +// users from attempting to instantiate a return value from `helper()`. +export type FunctionBasedHelper = abstract new () => FunctionBasedHelperInstance; + +/** + * In many cases, the ceremony of a full `Helper` class is not required. + * The `helper` method create pure-function helpers without instances. For + * example: + * ```app/helpers/format-currency.js + * import { helper } from '@ember/component/helper'; + * export default helper(function(params, hash) { + * let cents = params[0]; + * let currency = hash.currency; + * return `${currency}${cents * 0.01}`; + * }); + * ``` + */ +// This overload allows users to write types directly on the callback passed to +// the `helper` function and infer the resulting type correctly. +export function helper

( + helperFn: (positional: P, named: N) => R, +): FunctionBasedHelper<{ + Args: { + Positional: P; + Named: N; + }; + Return: R; +}>; + +// This overload allows users to provide a `Signature` type explicitly at the +// helper definition site, e.g. `helper((pos, named) => {...})`. **Note:** +// this overload must appear second, since TS' inference engine will not +// correctly infer the type of `S` here from the types on the supplied callback. +export function helper( + helperFn: (positional: PositionalArgs, named: NamedArgs) => Return, +): FunctionBasedHelper<{ + Args: { + Positional: PositionalArgs; + Named: NamedArgs; + }; + Return: Return; +}>; + +export {}; diff --git a/types/preview/@ember/component/index.d.ts b/types/preview/@ember/component/index.d.ts new file mode 100644 index 00000000000..069e9d2c923 --- /dev/null +++ b/types/preview/@ember/component/index.d.ts @@ -0,0 +1,131 @@ +import CoreView from '@ember/component/-private/core-view'; +import ClassNamesSupport from '@ember/component/-private/class-names-support'; +import ViewMixin from '@ember/component/-private/view-mixin'; +import { ComponentManager, Capabilities } from './-private/glimmer-interfaces'; +import { Opaque } from 'ember/-private/type-utils'; + +// Re-export these types so people can use them! +export { ComponentManager, Capabilities }; + +interface TemplateFactory { + __htmlbars_inline_precompile_template_factory: any; +} + +// The generic here is for a *signature: a way to hang information for tools +// like Glint which can provide typey checking for component templates using +// information supplied via this generic. While it may appear useless on this +// class definition and extension, it is used by external tools and should not +// be removed. +// tslint:disable-next-line:no-unnecessary-generics +export default interface Component extends ViewMixin, ClassNamesSupport, Opaque {} +export default class Component extends CoreView { + // methods + readDOMAttr(name: string): string; + // properties + /** + * The WAI-ARIA role of the control represented by this view. For example, a button may have a + * role of type 'button', or a pane may have a role of type 'alertdialog'. This property is + * used by assistive software to help visually challenged users navigate rich web applications. + */ + ariaRole: string; + /** + * The HTML id of the component's element in the DOM. You can provide this value yourself but + * it must be unique (just as in HTML): + * + * If not manually set a default value will be provided by the framework. Once rendered an + * element's elementId is considered immutable and you should never change it. If you need + * to compute a dynamic value for the elementId, you should do this when the component or + * element is being instantiated: + */ + elementId: string; + /** + * A component may contain a layout. A layout is a regular template but supersedes the template + * property during rendering. It is the responsibility of the layout template to retrieve the + * template property from the component (or alternatively, call Handlebars.helpers.yield, + * {{yield}}) to render it in the correct location. This is useful for a component that has a + * shared wrapper, but which delegates the rendering of the contents of the wrapper to the + * template property on a subclass. + */ + layout: TemplateFactory | string; + /** + * Enables components to take a list of parameters as arguments. + */ + static positionalParams: string[] | string; + // events + /** + * Called when the attributes passed into the component have been updated. Called both during the + * initial render of a container and during a rerender. Can be used in place of an observer; code + * placed here will be executed every time any attribute updates. + */ + didReceiveAttrs(): void; + /** + * Called after a component has been rendered, both on initial render and in subsequent rerenders. + */ + didRender(): void; + /** + * Called when the component has updated and rerendered itself. Called only during a rerender, + * not during an initial render. + */ + didUpdate(): void; + /** + * Called when the attributes passed into the component have been changed. Called only during a + * rerender, not during an initial render. + */ + didUpdateAttrs(): void; + /** + * Called before a component has been rendered, both on initial render and in subsequent rerenders. + */ + willRender(): void; + /** + * Called when the component is about to update and rerender itself. Called only during a rerender, + * not during an initial render. + */ + willUpdate(): void; + + /** + * `reopen()` was deprecated and removed from `Component`. It is given an + * illegitimate type in these types so that you cannot call it or use it! + * Unfortunately, it cannot actually be *removed* from this type, because TS + * rightly complains that `Component` is no longer a valid subtype of the + * `EmberObject` base class, and will not let you use it. + */ + static reopen(): never; +} + +/** + * Associate a class with a component manager (an object that is responsible for + * coordinating the lifecycle events that occurs when invoking, rendering and + * re-rendering a component). + * + * @param managerFactory a function to create the owner for an object + * @param object the object to associate with the componetn manager + * @return the same object passed in, now associated with the manager + */ +export function setComponentManager( + managerFactory: (owner: unknown) => ComponentManager, + object: T +): T; + +// In normal TypeScript, these built-in components are essentially opaque tokens +// that just need to be importable. Declaring them with unique interfaces +// like this, however, gives tools like Glint (that DO have a richer +// notion of what they are) a place to install more detailed type information. +export interface Input extends Opaque<'component:input'> {} +export interface Textarea extends Opaque<'component:textarea'> {} + +/** + * The `Input` component lets you create an HTML `` element. + * + * @see https://api.emberjs.com/ember/4.1/classes/Ember.Templates.components/methods/Input?anchor=Input + */ +export const Input: Input; + +/** + * The `Textarea` component inserts a new instance of `