Skip to content

Commit d7dbb2f

Browse files
waitingsongpopomore
authored andcommitted
fix: export class of DefaultConfig (#38)
tsc throw errors when tsconfig.json set "declaration": true config/defaultConfig.ts(9,1): error TS4082: Default export of the module has or is using private name 'DefaultConfig'. config/defaultConfig.ts(13,28): error TS4033: Property 'config' of exported interface has or is using private name 'DefaultConfig'. define interface NewsItem as return type of HackerNews.getItem() for types recognition app/controller/news.ts: variable newsList can be recognized as type of NewsItem[] correctly instead of an object missing array
1 parent 3afdaf8 commit d7dbb2f

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

hackernews-async-ts/app/router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Application } from 'egg';
2-
module.exports = (app: Application) => {
2+
3+
export default (app: Application) => {
34
const controller = app.controller;
45
app.redirect('/', '/news');
56
app.get('/news', controller.news.list);

hackernews-async-ts/app/service/HackerNews.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import { Context, Service } from 'egg';
22

3+
export interface NewsItem {
4+
id: number;
5+
score: number;
6+
time: number;
7+
title: string;
8+
type: string;
9+
url: string;
10+
descendants: number;
11+
kids: number[];
12+
by: string;
13+
}
14+
315
/**
416
* HackerNews Api Service
517
*/
6-
export default class HackerNews extends Service {
18+
export class HackerNews extends Service {
719
constructor(ctx: Context) {
820
super(ctx);
921
}
@@ -54,17 +66,7 @@ export default class HackerNews extends Service {
5466
* query item
5567
* @param id - itemId
5668
*/
57-
public async getItem(id: number): Promise<{
58-
id: number;
59-
score: number;
60-
time: number;
61-
title: string;
62-
type: string;
63-
url: string;
64-
descendants: number;
65-
kids: number[];
66-
by: string;
67-
}> {
69+
public async getItem(id: number): Promise<NewsItem> {
6870
return await this.request(`item/${id}.json`);
6971
}
7072

@@ -76,3 +78,5 @@ export default class HackerNews extends Service {
7678
return await this.request(`user/${id}.json`);
7779
}
7880
}
81+
82+
export default HackerNews;

hackernews-async-ts/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'path';
55
import 'source-map-support/register';
66
import defaultConfig from './defaultConfig';
77

8-
module.exports = (appInfo: EggAppConfig) => {
8+
export default (appInfo: EggAppConfig) => {
99
const config: any = {};
1010

1111
// should change to your own

hackernews-async-ts/config/defaultConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class DefaultConfig {
1+
export class DefaultConfig {
22
news = {
33
pageSize: 30,
44
serverUrl: 'https://hacker-news.firebaseio.com/v0',

0 commit comments

Comments
 (0)