// eslint-disable-next-line @definitelytyped/no-self-import import Mixin from "@ember/object/mixin"; // eslint-disable-next-line @definitelytyped/no-self-import import ComputedProperty from "@ember/object/computed"; /** * Map type `T` to a plain object hash with the identity mapping. * * Discards any additional object identity like the ability to `new()` up the class. * The `new()` capability is added back later by merging `EmberClassConstructor` * * Implementation is carefully chosen for the reasons described in * https://github.com/typed-ember/ember-typings/pull/29 */ export type Objectify = Readonly; export type ExtractPropertyNamesOfType = { [K in keyof T]: T[K] extends S ? K : never; }[keyof T]; export type Fix = { [K in keyof T]: T[K] }; /** * Used to capture type information about a computed property, both * the type of its value and (if it differs) the type its setter expects * to receive. * * Note that this is intentionally a `class` and not a `type` or * `interface` so that we can sneak in private fields that capture * type info for the computed property without impacting the * user-visible type. */ declare class ComputedPropertyMarker { // Necessary in order to avoid losing type information // see: https://github.com/typed-ember/ember-cli-typescript/issues/246#issuecomment-414812013 private [GetType]: Get; private [SetType]: Set; } export type { ComputedPropertyMarker }; declare const GetType: unique symbol; declare const SetType: unique symbol; /** * Used to infer the type of ember classes of type `T`. * * Generally you would use `EmberClass.create()` instead of `new EmberClass()`. * * The single-arg constructor is required by the typescript compiler. * The multi-arg constructor is included for better ergonomics. * * Implementation is carefully chosen for the reasons described in * https://github.com/typed-ember/ember-typings/pull/29 */ export type EmberClassConstructor = (new(properties?: object) => T) & (new(...args: any[]) => T); /** * Check that any arguments to `create()` match the type's properties. * * Accept any additional properties and add merge them into the instance. */ export type EmberInstanceArguments = Partial & { [key: string]: any; }; /** * Accept any additional properties and add merge them into the prototype. */ export interface EmberClassArguments { [key: string]: any; } /** * Ember.Object.extend(...) accepts any number of mixins or literals. */ export type MixinOrLiteral = Mixin | T; /** * Deconstructs computed properties into the types which would be returned by `.get()`. */ export type UnwrapComputedPropertyGetter = T extends ComputedPropertyMarker ? U : T; export type UnwrapComputedPropertyGetters = { [P in keyof T]: UnwrapComputedPropertyGetter; }; export type UnwrapComputedPropertySetter = T extends ComputedPropertyMarker ? V : T; export type UnwrapComputedPropertySetters = { [P in keyof T]: UnwrapComputedPropertySetter; }; export type ComputedPropertyGetterFunction = (this: any, key: string) => T; export type ComputedPropertySetterFunction = (this: any, key: string, newVal: T, oldVal: T) => T; export interface ComputedPropertyGetterObj { get(this: any, key: string): T; } export interface ComputedPropertySetterObj { set(this: any, key: string, value: T): T; } export type ComputedPropertyObj = | ComputedPropertyGetterObj | ComputedPropertySetterObj | (ComputedPropertyGetterObj & ComputedPropertySetterObj); export type ComputedPropertyGetter = ComputedPropertyGetterFunction | ComputedPropertyGetterObj; export type ComputedPropertySetter = ComputedPropertySetterFunction | ComputedPropertySetterObj; export type ComputedPropertyCallback = | ComputedPropertyGetterFunction | ComputedPropertyObj; export type ObserverMethod = | keyof Target | ((this: Target, sender: Sender, key: string, value: any, rev: number) => void); // This type looks weird, but is correct: from a list of "bottom" to "top", in // type theory terms. export type AnyFunction = (...args: never[]) => unknown;