From 48efbe54582f9ff64f1e47024bbce2c402727748 Mon Sep 17 00:00:00 2001 From: Emiliano Leite Date: Tue, 8 Oct 2019 21:08:51 -0300 Subject: [PATCH] Create types for react-native-rss-parser (#38960) * feat(@types/react-native-rss-parser): Create types * feat(@types/react-native-rss-parser): Add itunes prop --- types/react-native-rss-parser/index.d.ts | 83 +++++++++++++++++++ .../react-native-rss-parser-tests.ts | 18 ++++ types/react-native-rss-parser/tsconfig.json | 23 +++++ types/react-native-rss-parser/tslint.json | 1 + 4 files changed, 125 insertions(+) create mode 100644 types/react-native-rss-parser/index.d.ts create mode 100644 types/react-native-rss-parser/react-native-rss-parser-tests.ts create mode 100644 types/react-native-rss-parser/tsconfig.json create mode 100644 types/react-native-rss-parser/tslint.json diff --git a/types/react-native-rss-parser/index.d.ts b/types/react-native-rss-parser/index.d.ts new file mode 100644 index 0000000000..65929cbace --- /dev/null +++ b/types/react-native-rss-parser/index.d.ts @@ -0,0 +1,83 @@ +// Type definitions for react-native-rss-parser 1.4 +// Project: https://github.com/jameslawler/react-native-rss-parser +// Definitions by: Emiliano Leite +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.3 + +export { }; + +type Maybe = T | undefined; + +export interface FeedItem { + id: string; + title: string; + links: Array<{ + url: string; + rel: string; + }>; + description: string; + content: string; + authors: Array>; + categories: Array>; + published: string; + enclosures: Array<{ + url: string; + length: string; + mimeType: string; + }>; + itunes: { + authors: Maybe>; + block: Maybe; + duration: string; + explicit: string; + image: Maybe; + isClosedCaptioned: Maybe; + order: Maybe; + subtitle: string; + summary: Maybe; + }; +} + +export interface Feed { + type: string; + title: string; + links: Array<{ + url: string; + rel: string; + }>; + description: string; + language: string; + copyright: Maybe; + authors: Array>; + lastUpdated: string; + lastPublished: string; + categories: Array>; + image: { + title: string; + description: Maybe; + url: string; + height: Maybe; + width: Maybe; + }; + itunes: { + authors: Array<{ name: string }>; + block: Maybe; + categories: Array<{ + name: string; + subCategories: Array>; + }>; + complete: Maybe; + explicit: string; + image: string; + newFeedUrl: Maybe; + owner: { + name: string; + email: string; + }; + subtitle: Maybe; + summary: string; + }; + items: FeedItem[]; +} + +export function parse(feedUrl: string): Promise; diff --git a/types/react-native-rss-parser/react-native-rss-parser-tests.ts b/types/react-native-rss-parser/react-native-rss-parser-tests.ts new file mode 100644 index 0000000000..3c0420b8ee --- /dev/null +++ b/types/react-native-rss-parser/react-native-rss-parser-tests.ts @@ -0,0 +1,18 @@ +import { parse } from 'react-native-rss-parser'; + +// -- Globals -- +declare const fetch: (url: string) => Promise; +declare const console: any; + +fetch('http://rss-url.com') + .then(response => response.text()) + .then(parse) + .then(feed => { + feed.authors[0].name; // $ExpectError + feed.image.title.toUpperCase(); // $ExpectType string + feed.image.height.toUpperCase(); // $ExpectError + + feed.items[0].id; // $ExpectType string + feed.items[0].authors.name; // $ExpectError + }) + .catch(console.error); diff --git a/types/react-native-rss-parser/tsconfig.json b/types/react-native-rss-parser/tsconfig.json new file mode 100644 index 0000000000..8be573b8be --- /dev/null +++ b/types/react-native-rss-parser/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-native-rss-parser-tests.ts" + ] +} diff --git a/types/react-native-rss-parser/tslint.json b/types/react-native-rss-parser/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-rss-parser/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }