diff --git a/js-data/js-data-tests.ts b/js-data/js-data-tests.ts index 1cb3e8e728..a6ac09a42d 100644 --- a/js-data/js-data-tests.ts +++ b/js-data/js-data-tests.ts @@ -90,13 +90,13 @@ var UserWithComputedProperty = store.defineResource({ 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 -} \ No newline at end of file +} + +/** + * 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 +} + +interface MyResourceDefinition { + +} + +module JSData_ { + + interface DS { + + definitions: MyCustomDataStore; + } +} + +var store = new JSData.DS(); + +var myResourceDefinition = store.defineResource('myResource'); + +myResourceDefinition = store.definitions.myResource; \ No newline at end of file diff --git a/js-data/js-data.d.ts b/js-data/js-data.d.ts index 13fc5e6910..b7271c4e23 100644 --- a/js-data/js-data.d.ts +++ b/js-data/js-data.d.ts @@ -16,7 +16,7 @@ // defining what exists in JSData and how it looks declare module JSData_ { - class JSDataPromise extends Promise { + interface JSDataPromise extends Promise { // enhanced with finally finally(finallyCb?:() => U):Promise; @@ -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; @@ -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