-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add tsd #1027
Merged
feat: add tsd #1027
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.js | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Controller } from 'egg'; | ||
|
||
// add user controller and service | ||
declare module 'egg' { | ||
interface IController { | ||
foo: FooController; | ||
} | ||
} | ||
|
||
// controller | ||
export default class FooController extends Controller { | ||
async getData() { | ||
this.ctx.body = await this.ctx.service.foo.bar(); | ||
} | ||
async getBar() { | ||
this.ctx.body = await this.service.foo.bar(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Application } from 'egg'; | ||
|
||
export default (app: Application) => { | ||
const controller = app.controller; | ||
app.get('/foo', controller.foo.getData); | ||
app.post('/', controller.foo.getData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Service } from 'egg'; | ||
|
||
// add user controller and service | ||
declare module 'egg' { | ||
interface IService { | ||
foo: FooService; | ||
} | ||
} | ||
|
||
export default class FooService extends Service { | ||
async bar() { | ||
return { env: this.config.env }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
keys: 'foo', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "app-ts", | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"baseUrl": ".", | ||
"paths": { | ||
"egg": ["../../../../index"] | ||
}, | ||
"module": "commonjs", | ||
"lib": ["es7"], | ||
"strict": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const request = require('supertest'); | ||
const mm = require('egg-mock'); | ||
const runscript = require('runscript'); | ||
const path = require('path'); | ||
const utils = require('../utils'); | ||
const baseDir = path.join(__dirname, '../fixtures/apps/app-ts'); | ||
|
||
describe('test/ts/index.test.js', () => { | ||
before(function* () { | ||
if (process.env.CI) { | ||
yield runscript('tsc && npmlink ../../../../', { cwd: baseDir }); | ||
} else { | ||
yield runscript('tsc && npm link ../../../../', { cwd: baseDir }); | ||
} | ||
}); | ||
|
||
describe('compiler code', () => { | ||
|
||
afterEach(mm.restore); | ||
let app; | ||
before(function* () { | ||
app = utils.app('apps/app-ts'); | ||
yield app.ready(); | ||
}); | ||
after(function* () { | ||
yield app.close(); | ||
}); | ||
|
||
it('controller run ok', done => { | ||
request(app.callback()) | ||
.get('/foo') | ||
.expect(200) | ||
.expect({ env: 'unittest' }) | ||
.end(done); | ||
}); | ||
}); | ||
|
||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d.ts 的 entry 配置要配么
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d.ts 的 entry 配置
是什么意思?ts 默认会找包里面的 index.d.ts ,找不到找
@types/egg
的There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就是如果不放 index.d.ts 是否可以指定,类似 main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html 可以配置
types
字段,要配一个么?默认是 index.d.tsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
配吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加好了