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
This commit is contained in:
Emiliano Leite 2019-10-08 21:08:51 -03:00 committed by Armando Aguirre
parent 6b1b1e6d9b
commit 48efbe5458
4 changed files with 125 additions and 0 deletions

View File

@ -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 <https://github.com/emilianoLeite>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.3
export { };
type Maybe<T> = T | undefined;
export interface FeedItem {
id: string;
title: string;
links: Array<{
url: string;
rel: string;
}>;
description: string;
content: string;
authors: Array<Maybe<{ name: string }>>;
categories: Array<Maybe<{ name: string }>>;
published: string;
enclosures: Array<{
url: string;
length: string;
mimeType: string;
}>;
itunes: {
authors: Maybe<Array<{ name: string }>>;
block: Maybe<string>;
duration: string;
explicit: string;
image: Maybe<string>;
isClosedCaptioned: Maybe<string>;
order: Maybe<string>;
subtitle: string;
summary: Maybe<string>;
};
}
export interface Feed {
type: string;
title: string;
links: Array<{
url: string;
rel: string;
}>;
description: string;
language: string;
copyright: Maybe<string>;
authors: Array<Maybe<{ name: string }>>;
lastUpdated: string;
lastPublished: string;
categories: Array<Maybe<{ name: string }>>;
image: {
title: string;
description: Maybe<string>;
url: string;
height: Maybe<string>;
width: Maybe<string>;
};
itunes: {
authors: Array<{ name: string }>;
block: Maybe<string>;
categories: Array<{
name: string;
subCategories: Array<Maybe<{ name: string }>>;
}>;
complete: Maybe<string>;
explicit: string;
image: string;
newFeedUrl: Maybe<string>;
owner: {
name: string;
email: string;
};
subtitle: Maybe<string>;
summary: string;
};
items: FeedItem[];
}
export function parse(feedUrl: string): Promise<Feed>;

View File

@ -0,0 +1,18 @@
import { parse } from 'react-native-rss-parser';
// -- Globals --
declare const fetch: (url: string) => Promise<any>;
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);

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }