mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-03 16:50:15 +00:00
+ changing the JSData Promise type to interface
+ adding definitions object with usage example in tests for enabling custom type definitions of created resource definitions
This commit is contained in:
@@ -90,13 +90,13 @@ var UserWithComputedProperty = store.defineResource<IUserWithComputedProperty>({
|
||||
computed: {
|
||||
// each function's argument list defines the fields
|
||||
// that the computed property depends on
|
||||
fullName: ['first', 'last', function (first: string, last: string) {
|
||||
fullName: ['first', 'last', function (first:string, last:string) {
|
||||
return first + ' ' + last;
|
||||
}],
|
||||
// shortand, use the array syntax above if you want
|
||||
// you computed properties to work after you've
|
||||
// minified your code. Shorthand style won't work when minified
|
||||
initials: function (first: string, last: string) {
|
||||
initials: function (first:string, last:string) {
|
||||
return first.toUpperCase()[0] + '. ' + last.toUpperCase()[0] + '.';
|
||||
}
|
||||
}
|
||||
@@ -490,4 +490,33 @@ module CustomAdapterTest {
|
||||
var store = new JSData.DS();
|
||||
store.registerAdapter('mca', new MyCustomAdapter(), {default: true});
|
||||
// the data store will now use your custom adapter by default
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* showing the use of open ended interface to realize typings
|
||||
* on the Datastore.definitions object where all resource definitions
|
||||
* are saved.
|
||||
*/
|
||||
|
||||
interface MyCustomDataStore {
|
||||
|
||||
myResource: JSData_.DSResourceDefinition<MyResourceDefinition>
|
||||
}
|
||||
|
||||
interface MyResourceDefinition {
|
||||
|
||||
}
|
||||
|
||||
module JSData_ {
|
||||
|
||||
interface DS {
|
||||
|
||||
definitions: MyCustomDataStore;
|
||||
}
|
||||
}
|
||||
|
||||
var store = new JSData.DS();
|
||||
|
||||
var myResourceDefinition = store.defineResource<MyResourceDefinition>('myResource');
|
||||
|
||||
myResourceDefinition = store.definitions.myResource;
|
||||
9
js-data/js-data.d.ts
vendored
9
js-data/js-data.d.ts
vendored
@@ -16,7 +16,7 @@
|
||||
// defining what exists in JSData and how it looks
|
||||
declare module JSData_ {
|
||||
|
||||
class JSDataPromise<R> extends Promise<R> {
|
||||
interface JSDataPromise<R> extends Promise<R> {
|
||||
|
||||
// enhanced with finally
|
||||
finally<U>(finallyCb?:() => U):Promise<U>;
|
||||
@@ -30,6 +30,10 @@ declare module JSData_ {
|
||||
// rather undocumented
|
||||
errors:DSErrors;
|
||||
|
||||
// those are objects containing the defined resources and adapters
|
||||
definitions:any;
|
||||
adapters:any;
|
||||
|
||||
defaults:DSConfiguration;
|
||||
|
||||
changeHistory(resourceName:string, id?:string):Array<Object>;
|
||||
@@ -394,7 +398,8 @@ declare module JSData_ {
|
||||
|
||||
// declaring the existing global js object
|
||||
declare var JSData:{
|
||||
DS: JSData_.DS
|
||||
DS: JSData_.DS;
|
||||
DSErrors: JSData_.DSErrors;
|
||||
};
|
||||
|
||||
//Support node require
|
||||
|
||||
Reference in New Issue
Block a user