From 9878248e8d2bf54e2015d4f7f380d46a23a8102f Mon Sep 17 00:00:00 2001 From: StefanSchoof Date: Fri, 9 Jun 2017 14:15:16 +0200 Subject: [PATCH 1/3] Use ts 2.1 keyof Feature --- types/sharepoint/index.d.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/types/sharepoint/index.d.ts b/types/sharepoint/index.d.ts index 3520e12f06..1d056448a4 100644 --- a/types/sharepoint/index.d.ts +++ b/types/sharepoint/index.d.ts @@ -2,6 +2,7 @@ // Project: https://msdn.microsoft.com/en-us/library/office/jj193034.aspx // Definitions by: Stanislav Vyshchepan , Andrey Markeev // Definitions: https:// github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1. /// @@ -3538,7 +3539,7 @@ declare namespace SP { newMode } /** Represents a list on a SharePoint Web site. */ - class List extends SP.SecurableObject { + class List extends SP.SecurableObject { /** Gets item by id. */ getItemById(id: number): SP.ListItem; /** Gets a value that specifies whether the list supports content types. */ @@ -3750,20 +3751,20 @@ declare namespace SP { /** Sends the list to the site recycle bin. */ recycle(): SP.GuidResult; /** Returns collection of list items based on the specified CAML query. */ - getItems(query: SP.CamlQuery): SP.ListItemCollection; + getItems(query: SP.CamlQuery): SP.ListItemCollection; /** Creates a new list item in the list. */ addItem(parameters: SP.ListItemCreationInformation): SP.ListItem; } /** Represents a collection of SP.List objects */ class ListCollection extends SP.ClientObjectCollection { /** Gets the list at the specified index in the collection. */ - itemAt(index: number): SP.List; + itemAt(index: number): SP.List; /** Gets the list at the specified index in the collection. */ - get_item(index: number): SP.List; + get_item(index: number): SP.List; /** Returns the list with the specified title from the collection. */ - getByTitle(title: string): SP.List; + getByTitle(title: string): SP.List; /** Returns the list with the specified list identifier. */ - getById(id: string | SP.Guid): SP.List; + getById(id: string | SP.Guid): SP.List; /** Creates a new list or a document library. */ add(parameters: SP.ListCreationInformation): SP.List; /** Gets a list that is the default location for wiki pages. */ @@ -3830,12 +3831,12 @@ declare namespace SP { textField, } /** Represents an item or row in a list. */ - class ListItem extends SP.SecurableObject { - get_fieldValues(): any; + class ListItem extends SP.SecurableObject { + get_fieldValues(): T; /** Gets the specified field value for the list item. Field value is returned as string, but it can be casted to a specific field value type, e.g. SP.LookupFieldValue, etc. */ - get_item(fieldInternalName: string): any; + get_item(fieldInternalName: K): T[K]; /** Sets the specified field value for the list item. Consider using parseAndSetFieldValue instead. */ - set_item(fieldInternalName: string, value: any): void; + set_item(fieldInternalName: K, value: T[K]): void; /** Gets collection of objects that represent attachments for the list item. */ get_attachmentFiles(): SP.AttachmentCollection; /** Gets the content type of the item. */ @@ -3878,10 +3879,10 @@ declare namespace SP { /** Validates form values specified for the list item. Errors are returned through hasException and errorMessage properties of the ListItemFormUpdateValue objects */ validateUpdateListItem(formValues: SP.ListItemFormUpdateValue[], bNewDocumentUpdate: boolean): SP.ListItemFormUpdateValue[]; } - class ListItemCollection extends SP.ClientObjectCollection { - itemAt(index: number): SP.ListItem; - get_item(index: number): SP.ListItem; - getById(id: number | string): SP.ListItem; + class ListItemCollection extends SP.ClientObjectCollection> { + itemAt(index: number): SP.ListItem; + get_item(index: number): SP.ListItem; + getById(id: number | string): SP.ListItem; get_listItemCollectionPosition(): SP.ListItemCollectionPosition; } class ListItemCollectionPosition extends SP.ClientValueObject { From 13f2c9175e0eb8f98687dea92a9a437daba4c950 Mon Sep 17 00:00:00 2001 From: StefanSchoof Date: Fri, 9 Jun 2017 14:21:31 +0200 Subject: [PATCH 2/3] Bump required version to 2.3 --- types/sharepoint/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/sharepoint/index.d.ts b/types/sharepoint/index.d.ts index 1d056448a4..dca11083a6 100644 --- a/types/sharepoint/index.d.ts +++ b/types/sharepoint/index.d.ts @@ -2,7 +2,7 @@ // Project: https://msdn.microsoft.com/en-us/library/office/jj193034.aspx // Definitions by: Stanislav Vyshchepan , Andrey Markeev // Definitions: https:// github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1. +// TypeScript Version: 2.3 /// From e13ac9613f37db7a3ba35230ad66f80bffa9017a Mon Sep 17 00:00:00 2001 From: StefanSchoof Date: Fri, 9 Jun 2017 14:26:08 +0200 Subject: [PATCH 3/3] Add Test --- types/sharepoint/sharepoint-tests.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/sharepoint/sharepoint-tests.ts b/types/sharepoint/sharepoint-tests.ts index 20555d0cd5..63fd693fcc 100644 --- a/types/sharepoint/sharepoint-tests.ts +++ b/types/sharepoint/sharepoint-tests.ts @@ -370,11 +370,16 @@ function deleteFolder(resultpanel: HTMLElement) { } } +interface Announcements { + Title: string; + Body: string; +} + // List item tasks function readItems(resultpanel: HTMLElement) { const clientContext = SP.ClientContext.get_current(); const oWebsite = clientContext.get_web(); - const oList = oWebsite.get_lists().getByTitle("Announcements"); + const oList = oWebsite.get_lists().getByTitle("Announcements"); const camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml( '' +