Skip to content

Commit

Permalink
Merge pull request #207 from Sitebase/bug/types
Browse files Browse the repository at this point in the history
[typescript] fix broken typescript definitions
  • Loading branch information
JorgenEvens authored Jun 2, 2020
2 parents 1d6d7b2 + a4603a5 commit 1a2506c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 17 deletions.
61 changes: 61 additions & 0 deletions demo/type-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* This file contains a very small demo project
* that is tested for type correctness in the
* `npm run test:type-check` check.
*
* This file is intended to include any API interface
* to ensure that our type definitions are correct.
*/

import React, { Component } from 'react';
import Avatar, {
createAvatarComponent,
ConfigProvider,
Cache,

GravatarSource,
FacebookSource,
GithubSource,
SkypeSource,
ValueSource,
SrcSource,
IconSource,

VKontakteSource,
InstagramSource,
TwitterSource,
GoogleSource,
} from '..';

const CustomAvatar = createAvatarComponent({
sources: [
GravatarSource,
FacebookSource,
GithubSource,
SkypeSource,
ValueSource,
SrcSource,
IconSource,
VKontakteSource,
InstagramSource,
TwitterSource,
GoogleSource,
]
});

export default
class TypeTest extends Component {

render() {
return (
<div>
<Avatar />
<CustomAvatar />

<ConfigProvider>
<Avatar />
</ConfigProvider>
</div>
)
}
}
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ interface Source {

type SourceConstructor = new (props: object) => Source;

const AvatarRedirectSource: SourceConstructor;
export const RedirectSource: (network: string, property: string) => AvatarRedirectSource
export const RedirectSource: (network: string, property: string) => SourceConstructor

/**
* Universal avatar makes it possible to fetch/generate an avatar based on the information you have about that user.
* We use a fallback system that if for example an invalid Facebook ID is used it will try Google, and so on.
*/
declare const ReactAvatar: React.ComponentType<ReactAvatarProps>;
type ReactAvatar = React.ComponentType<ReactAvatarProps>;
declare const Avatar : ReactAvatar;

export const createAvatarComponent: (options: CreateAvatarOptions) => ReactAvatar;

Expand All @@ -184,4 +184,4 @@ export const InstagramSource: SourceConstructor;
export const TwitterSource: SourceConstructor;
export const GoogleSource: SourceConstructor;

export default ReactAvatar;
export default Avatar;
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"demo": "npm -s run build:demo",
"dev": "webpack-dev-server",
"serve": "npm -s run dev",
"test": "npm -s run test:lint && npm -s run test:tslint",
"test": "npm -s run test:lint && npm -s run test:type-check",
"test:lint": "eslint src",
"test:tslint": "tslint ./index.d.ts",
"test:type-check": "tsc -p tsconfig.json",
"postpublish": "npm -s run publish:docs",
"publish:docs": "npm -s run build:demo && gh-pages -d build"
},
Expand Down Expand Up @@ -59,8 +59,7 @@
"gh-pages": "^2.1.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"tslint": "^6.1.2",
"typescript": "^3.8.3",
"typescript": "^3.9.3",
"webpack": "^4.41.4",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-cli": "^3.3.10",
Expand Down
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"jsx": "react",
"noEmit": true,
"strict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
}
}
9 changes: 0 additions & 9 deletions tslint.json

This file was deleted.

0 comments on commit 1a2506c

Please sign in to comment.