김병진 x Flitto
userService.insertUser(user, function(res) {
...
});
insertUser(user, callback) {
return $http.post('/api/users', user);
}
router.route('/users')
.post(checkPermission, function(req, res, next) {
userService.insertUser(req.body.user, function(err, result) {
return res.send(result);
});
})
insertUserService(options, callback) {
userModel.insert(options.users, callback);
}
userService.insertUser(user, function(res) {
debugger
});
insertUser(user, callback) {
debugger
return $http.post('/api/users', user);
}
router.route('/users')
.post(checkPermission, function(req, res, next) {
userService.insertUser(req.user, function(err, result) {
debugger
return res.send(result);
});
})
insertUserService(options, callback) {
debugger
userModel.insert(options.users, callback);
}
userService.insertUser()
INPUT
??????
OUTPUT
??????????
if ( typeof data.username === 'string') ....
if ( typeof data.username === 'string') ....
if ( typeof data.username === 'string') ....
if ( typeof data.username === 'string') ....
if ( typeof data.username === 'string') ....
if ( typeof data.username === 'string') ....
if ( typeof data.username === 'string') ....
if ( typeof data.username === 'string') ....
if ( typeof data.username === 'string') ....
if ( typeof data.username === 'string') ....
if ( typeof data.username === 'string') ....
function greeter(person: string) {
return "Hello, " + person;
}
let user = [1,2,3];
greeter(user)
index.ts
$ tsc index.ts
error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'string'.
$ npm install -g typescript
userService.insertUser()
INPUT
??????
OUTPUT
??????????
interface User {
id?: string;
username: string;
email: string;
}
interface User {
id?: string;
username: string;
email: string;
}
interface Settings {
allow_email: string;
allow_push: string;
language: string;
}
interface UserWithSettings {
user: User;
settings: Settings;
}
interface Account {
account_name: string;
rrn: string;
}
interface Settings {
allow_email: string;
allow_push: string;
language: string;
}
interface User extends Settings, Account {
id?: string;
username: string;
email: string;
}
import {User} from '../interfaces/User';
...
userService.insertUser(user: User)
.subscribe(res => {
this.user = res;
});
import {User} from '../interfaces/User';
...
insertUser(user: User) {
return this.http.post('/api/users', {user});
}
userService.insertUser()
INPUT
Interface User
OUTPUT
??????????
userService.insertUser(user: User)
.subscribe(res => {
this.user = res;
})
userService.insertUser(user: User): Observable<User> {
return this.http.post<User>('/api/users', {user});
}
userService.insertUser()
INPUT
userInterface
OUTPUT
Observable<userInterface>
import {User} from '../interfaces/User';
...
router.route('/users')
.post(checkPermission, (req, res, next) => {
const user: User = {
username: req.body.user.username,
email: req.body.user.email
}
userService.insertUser(user) {
return res.send(result);
});
});
import {User} from '../interfaces/User';
...
insertUserService(user: User): Promise<User> {
return userModel.insert(options.users);
}
Front-end
Back-end
UserInterface
UserInterface
Front-end
Back-end
UserInterface
interface User {
id?: string;
username: string;
email: string;
}
import {User} from "../../../../shared/interfaces/user";
export class UserService {
insertUser(user: User) {
...
}
}
import {User} from "../../shared/interfaces/user";
export class UserService {
insertUser(user: User) {
...
}
}
back-end
front-end
shared
function Logger(target) {
console.log(`${target.name} is declared`)
}
@Logger
class Greeter {
say() {
console.log('hi');
}
}
$ tsc index.ts --experimentalDecorators
Greeter is declared
framework for Express
with TypeScript and Decorators
@ServerSettings({
rootDir,
mount: {
'': `${rootDir}/**/**Controller.js`
},
port: config.port,
acceptMimes: ['application/json'],
componentsScan: [
`${rootDir}/**/**Service.js`
],
serveStatic: {
'/': path.join(rootDir, '../public')
}
})
export default class Server extends ServerLoader {
...
}
router.route('/users')
.post(checkPermission, (req, res, next) => {
const user: User = {
username: req.user.username,
email: req.user.email
}
userService.insertUser(user) {
return res.send(result);
});
})
router.route('/orders')
.post(checkPermission, (req, res, next) => {
const order: Order = {
order_num: req.body.orders.order_num,
type: req.body.orders.type
}
orderService.insertOrder(order) {
return res.send(result);
});
})
router.route('/users')
.post(checkPermission, (req, res, next) => {
const user: User = {
username: req.body.user.username,
email: req.body.user.email
}
userService.insertUser(user) {
return res.send(result);
});
})
@Controller('/users')
export default class UserController {
@Post('')
@Authenticated('users')
async insertUser(
@Required() @BodyParams('user') user: User
) {
return this.userService(user);
}
}
@Service()
export default class UserService {
constructor(private sequelize: SequelizeService) {
}
async insertUser(user: User): Promise<User> {
...
}
}
@Controller('/users')
export default class UserController {
construct(private userService: UserService)
}
class UserService() {
insertUser(user: User) {
,
}
}
server/userService.ts(9,1): error TS1128: Declaration or statement expected.
export class AuthService {
constructor(user: User);
private _checkToken(): boolean;
private _getToken(logger: Logger): Promise<Token>;
signUp(user: User): Promise<User>;
...
}
auth.service.d.ts
https://www.npmjs.com/~types#packages
@Controller('/users')
export default class UserController implements OnServiceReady {
@Post('')
@Authenticated('users')
async insertUser(
@Required() @BodyParams('user') user: User
) {
return this.userService(user);
}
$onServiceReady() {
...
}
}
export abstract OnServiceReady {
$onServiceReady (): void;
}
.
.
.
함께 타입스크립트를 전 서비스에 도입할 개발자를 찾고 있습니다.
jobs@flitto.com
사실 저도 잘 몰라요..
bjkim.dev@gmail.com
우리 소통해요