mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
wip
This commit is contained in:
Vendored
+17
-180
@@ -1,187 +1,24 @@
|
||||
// Type definitions for Ember.js 2.8
|
||||
// Project: http://emberjs.com/
|
||||
// Definitions by: Jed Mao <https://github.com/jedmao>
|
||||
// bttf <https://github.com/bttf>
|
||||
// Derek Wickern <https://github.com/dwickern>
|
||||
// Chris Krycho <https://github.com/chriskrycho>
|
||||
// Theron Cross <https://github.com/theroncross>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
declare module 'ember' {
|
||||
// Get an alias to the global Array type to use in inner scope below.
|
||||
type GlobalArray<T> = T[];
|
||||
export type GlobalArray<T> = T[];
|
||||
|
||||
/**
|
||||
* Deconstructs computed properties into the types which would be returned by `.get()`.
|
||||
*/
|
||||
type ComputedProperties<T> = { [K in keyof T]: any };
|
||||
export type ComputedProperties<T> = { [K in keyof T]: any };
|
||||
|
||||
/**
|
||||
* 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<T>`
|
||||
*
|
||||
* Implementation is carefully chosen for the reasons described in
|
||||
* https://github.com/typed-ember/ember-typings/pull/29
|
||||
*/
|
||||
type Objectify<T> = Readonly<T>;
|
||||
export type EmberClassConstructor<T> = (new () => T) & (new (...args: any[]) => T);
|
||||
|
||||
type Fix<T> = { [K in keyof T]: T[K] };
|
||||
|
||||
/**
|
||||
* Ember.Object.extend(...) accepts any number of mixins or literals.
|
||||
*/
|
||||
type MixinOrLiteral<T, Base> = Ember.Mixin<T, Base> | T;
|
||||
|
||||
type EmberClassConstructor<T> = (new () => T) & (new (...args: any[]) => T);
|
||||
|
||||
export namespace Ember {
|
||||
/**
|
||||
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<T> {
|
||||
/**
|
||||
* 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`.
|
||||
*/
|
||||
objectsAt(indexes: number[]): Ember.Array<T>;
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* Adds an array observer to the receiving array. The array observer object
|
||||
* normally must implement two methods:
|
||||
*/
|
||||
addArrayObserver(target: {}, opts: {}): this;
|
||||
/**
|
||||
* Removes an array observer from the object if the observer is current
|
||||
* registered. Calling this method multiple times with the same object will
|
||||
* have no effect.
|
||||
*/
|
||||
removeArrayObserver(target: {}, opts: {}): this;
|
||||
/**
|
||||
* If you are implementing an object that supports `Ember.Array`, call this
|
||||
* method just before the array content changes to notify any observers and
|
||||
* invalidate any related properties. Pass the starting index of the change
|
||||
* as well as a delta of the amounts to change.
|
||||
*/
|
||||
arrayContentWillChange(startIdx: number, removeAmt: number, addAmt: number): this;
|
||||
/**
|
||||
* If you are implementing an object that supports `Ember.Array`, call this
|
||||
* method just after the array content changes to notify any observers and
|
||||
* invalidate any related properties. Pass the starting index of the change
|
||||
* as well as a delta of the amounts to change.
|
||||
*/
|
||||
arrayContentDidChange(startIdx: number, removeAmt: number, addAmt: number): this;
|
||||
}
|
||||
// Ember.Array rather than Array because the `array-type` lint rule doesn't realize the global is shadowed
|
||||
const Array: Mixin<Ember.Array<any>>;
|
||||
|
||||
/**
|
||||
An ArrayProxy wraps any other object that implements Ember.Array and/or Ember.MutableArray,
|
||||
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.
|
||||
**/
|
||||
interface ArrayProxy<T> {}
|
||||
/**
|
||||
AutoLocation will select the best location option based off browser support with the priority order: history, hash, none.
|
||||
**/
|
||||
class AutoLocation extends Object {}
|
||||
class CoreObject {
|
||||
static create<Instance, Args, T1>(
|
||||
this: EmberClassConstructor<Instance & ComputedProperties<Args>>,
|
||||
arg1: T1 & ThisType<Fix<T1 & Instance>>
|
||||
): Fix<Instance & T1>;
|
||||
|
||||
static extend<Statics, Instance extends B1, T1, B1>(
|
||||
this: Statics & EmberClassConstructor<Instance>,
|
||||
arg1: MixinOrLiteral<T1, B1> & ThisType<Fix<Instance & T1>>
|
||||
): Objectify<Statics> & EmberClassConstructor<T1 & Instance>;
|
||||
}
|
||||
/**
|
||||
* The `Ember.Mixin` class allows you to create mixins, whose properties can be
|
||||
* added to other classes.
|
||||
*/
|
||||
class Mixin<T, Base = Ember.Object> {
|
||||
/**
|
||||
* Mixin needs to have *something* on its prototype, otherwise it's treated like an empty interface.
|
||||
*/
|
||||
private __ember_mixin__: never;
|
||||
|
||||
static create<T, Base = Ember.Object>(
|
||||
args?: T & ThisType<Fix<T & Base>>
|
||||
): Mixin<T, Base>;
|
||||
}
|
||||
/**
|
||||
* 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<T> extends GlobalArray<T> {
|
||||
/**
|
||||
* __Required.__ You must implement this method to apply this mixin.
|
||||
*/
|
||||
length: number;
|
||||
|
||||
// NOTE: some array polyfill methods are re-declared here because their signatures
|
||||
// differ between typescript versions 2.4 and 2.6. Since we need to compile against
|
||||
// both, pick the more recent signature and re-declare it here as a tie-breaker.
|
||||
|
||||
/**
|
||||
* 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(
|
||||
predicate: (value: T, index: number, obj: T[]) => boolean,
|
||||
thisArg?: any
|
||||
): T | undefined;
|
||||
/**
|
||||
* 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(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T;
|
||||
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
|
||||
}
|
||||
const NativeArray: Mixin<NativeArray<any>>;
|
||||
class Object extends CoreObject.extend({}) {}
|
||||
class ArrayProxy<T> extends Object.extend({}) {
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
export interface ArrayProxy<T> {}
|
||||
export class CoreObject {
|
||||
static create<Instance, Args, T1>(
|
||||
this: EmberClassConstructor<Instance>,
|
||||
arg1: T1 & ThisType<T1 & Instance>
|
||||
): Instance & T1;
|
||||
|
||||
static extend<Statics, Instance, T1>(
|
||||
this: Statics & EmberClassConstructor<Instance>,
|
||||
arg1: T1 & ThisType<Instance & T1>
|
||||
): Statics & EmberClassConstructor<T1 & Instance>;
|
||||
}
|
||||
export interface NativeArray<T> extends GlobalArray<T> {}
|
||||
export class ArrayProxy<T> extends CoreObject {
|
||||
m(): T;
|
||||
}
|
||||
|
||||
export default Ember;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Ember from 'ember';
|
||||
import * as Ember from 'ember';
|
||||
|
||||
declare const arr: Ember.NativeArray<number>;
|
||||
let x: Ember.ArrayProxy<number> = Ember.ArrayProxy.create({ content: arr });
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
var App : any;
|
||||
|
||||
App = Em.Application.create<Em.Application>();
|
||||
|
||||
App.president = Em.Object.create({
|
||||
name: 'Barack Obama'
|
||||
});
|
||||
App.country = Em.Object.create({
|
||||
presidentNameBinding: 'MyApp.president.name'
|
||||
});
|
||||
App.country.get('presidentName');
|
||||
App.president = Em.Object.create({
|
||||
firstName: 'Barack',
|
||||
lastName: 'Obama',
|
||||
fullName: function () {
|
||||
return this.get('firstName') + ' ' + this.get('lastName');
|
||||
}.property()
|
||||
});
|
||||
App.president.get('fullName');
|
||||
|
||||
declare class MyPerson extends Em.Object {
|
||||
static createMan(): MyPerson;
|
||||
}
|
||||
|
||||
var Person1 = Em.Object.extend<typeof MyPerson>({
|
||||
say: (thing: string) => {
|
||||
alert(thing);
|
||||
}
|
||||
});
|
||||
|
||||
declare class MyPerson2 extends Em.Object {
|
||||
helloWorld(): void;
|
||||
}
|
||||
var tom = Person1.create<MyPerson2>({
|
||||
name: 'Tom Dale',
|
||||
helloWorld: function() {
|
||||
this.say('Hi my name is ' + this.get('name'));
|
||||
}
|
||||
});
|
||||
tom.helloWorld();
|
||||
|
||||
Person1.reopen({ isPerson: true });
|
||||
Person1.create<Em.Object>().get('isPerson');
|
||||
|
||||
Person1.reopenClass({
|
||||
createMan: () => {
|
||||
return Person1.create({ isMan: true });
|
||||
}
|
||||
});
|
||||
// ReSharper disable once DuplicatingLocalDeclaration
|
||||
declare var Person1: typeof MyPerson;
|
||||
Person1.createMan().get('isMan');
|
||||
|
||||
var person = Person1.create<Em.Object>({
|
||||
firstName: 'Yehuda',
|
||||
lastName: 'Katz'
|
||||
});
|
||||
person.addObserver('fullName', null, () => { });
|
||||
person.set('firstName', 'Brohuda');
|
||||
|
||||
App.todosController = Em.Object.create({
|
||||
todos: [
|
||||
Em.Object.create({ isDone: false })
|
||||
],
|
||||
remaining: (function() {
|
||||
var todos = this.get('todos');
|
||||
return todos.filterProperty('isDone', false).get('length');
|
||||
}).property('todos.@each.isDone')
|
||||
});
|
||||
|
||||
var todos = App.todosController.get('todos');
|
||||
var todo = todos.objectAt(0);
|
||||
todo.set('isDone', true);
|
||||
App.todosController.get('remaining');
|
||||
todo = Em.Object.create({ isDone: false });
|
||||
todos.pushObject(todo);
|
||||
App.todosController.get('remaining');
|
||||
|
||||
App.wife = Em.Object.create({
|
||||
householdIncome: 80000
|
||||
});
|
||||
App.husband = Em.Object.create({
|
||||
householdIncomeBinding: 'App.wife.householdIncome'
|
||||
});
|
||||
App.husband.get('householdIncome');
|
||||
App.husband.set('householdIncome', 90000);
|
||||
App.wife.get('householdIncome');
|
||||
|
||||
App.user = Em.Object.create({
|
||||
fullName: 'Kara Gates'
|
||||
});
|
||||
App.userView = Em.View.create({
|
||||
userNameBinding: Em.Binding.oneWay('App.user.fullName')
|
||||
});
|
||||
App.user.set('fullName', 'Krang Gates');
|
||||
App.userView.set('userName', 'Truckasaurus Gates');
|
||||
App.user.get('fullName');
|
||||
|
||||
App = Em.Application.create({
|
||||
rootElement: '#sidebar'
|
||||
});
|
||||
|
||||
var view = Em.View.create<Em.View>({
|
||||
templateName: 'say-hello',
|
||||
name: 'Bob'
|
||||
});
|
||||
view.appendTo('#container');
|
||||
view.append();
|
||||
view.remove();
|
||||
|
||||
App.AlertView = Em.View.extend({
|
||||
priority: 'p4',
|
||||
isUrgent: true
|
||||
});
|
||||
|
||||
App.ListingView = Em.View.extend({
|
||||
templateName: 'listing',
|
||||
edit: (event: any) => {
|
||||
event.view.set('isEditing', true);
|
||||
}
|
||||
});
|
||||
|
||||
App.userController = Em.Object.create({
|
||||
content: Em.Object.create({
|
||||
firstName: 'Albert',
|
||||
lastName: 'Hofmann',
|
||||
posts: 25,
|
||||
hobbies: 'Riding bicycles'
|
||||
})
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('highlight', function(property: string, options: any) {
|
||||
var value = Em.Handlebars.get(this, property, options);
|
||||
return new Handlebars.SafeString('<span class="highlight">' + value + '</span>');
|
||||
});
|
||||
|
||||
App.MyText = Em.TextField.extend({
|
||||
formBlurredBinding: 'App.adminController.formBlurred',
|
||||
change: function() {
|
||||
this.set('formBlurred', true);
|
||||
}
|
||||
});
|
||||
|
||||
var textArea = Em.TextArea.create({
|
||||
valueBinding: 'TestObject.value'
|
||||
});
|
||||
|
||||
App.ClickableView = Em.View.extend({
|
||||
click: () => {
|
||||
alert('ClickableView was clicked!');
|
||||
}
|
||||
});
|
||||
|
||||
var container = Em.ContainerView.create<Em.ContainerView>();
|
||||
container.append();
|
||||
var coolView = App.CoolView.create(),
|
||||
childViews = container.get('childViews');
|
||||
childViews.pushObject(coolView);
|
||||
|
||||
var Person2 = Em.Object.extend<typeof Em.Object>({
|
||||
sayHello: function() {
|
||||
console.log('Hello from ' + this.get('name'));
|
||||
}
|
||||
});
|
||||
var people = [
|
||||
Person2.create({ name: 'Juan' }),
|
||||
Person2.create({ name: 'Charles' }),
|
||||
Person2.create({ name: 'Majd' })
|
||||
];
|
||||
people.invoke('sayHello');
|
||||
|
||||
var arr = [Em.Object.create(), Em.Object.create()];
|
||||
arr.setEach('name', 'unknown');
|
||||
arr.getEach('name');
|
||||
|
||||
var Person3 = Em.Object.extend<typeof Em.Object>({
|
||||
name: null,
|
||||
isHappy: false
|
||||
});
|
||||
var people2 = [
|
||||
Person3.create({ name: 'Yehuda', isHappy: true }),
|
||||
Person3.create({ name: 'Majd', isHappy: false })
|
||||
];
|
||||
people2.every((person: Em.Object) => {
|
||||
return !!person.get('isHappy');
|
||||
});
|
||||
people2.some((person: Em.Object) => {
|
||||
return !!person.get('isHappy');
|
||||
});
|
||||
people2.everyProperty('isHappy', true);
|
||||
people2.someProperty('isHappy', true);
|
||||
|
||||
// Examples taken from http://emberjs.com/api/classes/Ember.RSVP.Promise.html
|
||||
var promise = new Ember.RSVP.Promise(function(resolve: Function, reject: Function) {
|
||||
// on success
|
||||
resolve('ok!');
|
||||
|
||||
// on failure
|
||||
reject('no-k!');
|
||||
});
|
||||
|
||||
promise.then(function(value: any) {
|
||||
// on fulfillment
|
||||
}, function(reason: any) {
|
||||
// on rejection
|
||||
});
|
||||
Vendored
-3491
File diff suppressed because it is too large
Load Diff
@@ -1,29 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": false,
|
||||
"strictNullChecks": false,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"ember": [
|
||||
"ember/v1"
|
||||
]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ember-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user