bluebird 3.0 ์ ์๋ ํ์ค es6 Promise ์ ์์ ํ ๋นํ ์ ์์ต๋๋ค.
Types of property 'then' are incompatible.
Type 'Bluebird<any>' is not assignable to type 'Promise<any>'.
/cc @lhecker
@Strate tsc์ ๋๋จธ์ง ์ถ๋ ฅ์ ๊ฒ์ํ ์ ์์ต๋๊น? ๊ทธ๋ฆฌ๊ณ ๋ก์ปฌ bluebird.d.ts
์ ์ด๊ณ #10831 ์์ ์ด ํ ์ค์ ์ถ๊ฐํ์ญ์์ค. ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๊น?
์ ์ฒด ์ค๋ฅ:
error TS2322: Type '(entity: BaseEntity) => Bluebird<{ contentType: "ActivityDesktopWidget" | "AddressType" | "Approv...' is not assignable to type 'UpdateEntityFunction<BaseEntity>'.
Type 'Bluebird<{ contentType: "ActivityDesktopWidget" | "AddressType" | "Approval" | "BaseIntegrationEn...' is not assignable to type 'Promise<BaseEntity>'.
Types of property 'then' are incompatible.
Type '{ <U>(onFulfill: (value: { contentType: "ActivityDesktopWidget" | "AddressType" | "Approval" | "B...' is not assignable to type '{ <TResult1, TResult2>(onfulfilled: (value: BaseEntity) => TResult1 | PromiseLike<TResult1>, onre...'.
Type 'Bluebird<any>' is not assignable to type 'Promise<any>'.
๋ด๊ฐ ์ฌ์ฉํ๊ณ [email protected]
๊ฐ์ง lib.es2016.d.ts
ํ์ผ. ํด๋น ์ค์ ์ถ๊ฐํด๋ ๋์์ด ๋์ง ์์ต๋๋ค.
๋ด๊ฐ ๋ณผ ์ ... ๋๋์ ์ํํ๋ค๊ณ ์๊ฐ ์ด ๋ผ์ธ์ด ๋๋ฝ ์ฌ๊ธฐ . ์ด๊ฒ์ ํ์ฌ ํ์ดํ์ผ๋ก onFulfill
๋ฟ๋ง ์๋๋ผ onReject
์์ ๋์ผํ ์ ํ U
์ ๋ฐํํด์ผ ํจ์ ์๋ฏธํฉ๋๋ค. ๋๊ตฐ๊ฐ npm๊ณผ ์ด dt ์ ์ฅ์ btw์์ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ค๋ฉด ์ ๋ง ์ข์ ๊ฒ์
๋๋ค.
๊ทธ ๋์์๋ .then(success, failure)
๋ฅผ .then(success).catch(failure)
๋ก ๋ถํ ํด์ผ ํ ๊ฒ์
๋๋ค. ๊ณต์ ๊ตฌ๋ฌธ์ ์ผ๋ถ์ด์ง๋ง ์ด์จ๋ bluebird์์ "์ ํธํ๋" ๊ฒ์ ์๋๋๋ค.
๋์์ ๋ค์๊ณผ ๊ฐ์ด ์ผ๋ฐ ๋งค๊ฐ๋ณ์ U
์๋์ผ๋ก ์ง์ ํ ์ ์๋ค๋ ๊ฒ์
๋๋ค.
.then<SomeType>(() => new SomeType(), (err) => 123); // This is an explicit error because SomeType != number
๋ ์ฝ๋ฐฑ์์ ๋์ผํ ์ ํ์ ๋ฐํํ๋์ง ํ์ธํฉ๋๋ค.
@lhecker ํ์ง๋ง then
๋๋ catch
๋ ์ฌ์ฉํ์ง ์์ต๋๋ค. ๋๋ ๊ทธ๋ฐ ๊ฒ์ด ์์ต๋๋ค :
// module 1. Note that bluebird is not imported
export default function<T>(promise: Promise<T>) {} // es6 promise used here
// module 2.
import Promise from "bluebird"
import handler from "./module1"
const promise: Promise<any>
handler(promise) // <-- error is here
bluebird.d.ts
es6์ ์ ์ธ๊ณผ ํธํ๋๋ ๋ ๋ค๋ฅธ then
์ ์ธ์ ์ถ๊ฐํ์ฌ ์์ ํ ์ ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ ์ ์ฅ... ์ฃ์กํฉ๋๋ค. ๋๋์ด ํด์์ ์ทจํด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค. ๐
๋ฐ๋ผ์ ๊ทธ๋์ ๋ฌด์์ ํด์ผ ํ๋์ง์ ๋ํ ๋ด ์๊ฒฌ์ ๋ฌด์ํ์ญ์์ค. ์ด์จ๋ ๋๋ฝ๋์ด ์๊ณ ์ด์ ๊ฐ์ ๊ธฐ๋ณธ ์ง์ ์ด์ธ์ ์์ ์ ํ ์๊ฐ์ด ์ค์ ๋ก ์๊ฑฐ๋ ์ ์ด๋ "ํด์๋ ์ ๋๊ธฐ ๋๋ฌธ์" ๋ค์๊ณผ ๊ฐ์ ๊ฒฝ์ฐ ํฌ๊ฒ ๊ฐ์ฌํ๊ฒ ์ต๋๋ค. PR์ ๋ณด๋ด ๋ ํ๋ก์ ํธ์ ํด๋น ํ์ดํ์ ์ถ๊ฐํ ์ ์์ต๋๋ค. ๐
@lhecker ์๋ฃ :)
์ฐธ๊ณ ๋ก ์ ๋ ์ฝ์์ ์๋ฝํ ๋ ํญ์ PromiseLike
๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ๋๋ถ๋ถ์ ์ฝ์์ ์๋ฝํ ์ ์๋๋ก ๊ตฌํ๋ ์ต์ ์ฝ์ ์ธํฐํ์ด์ค๋ฅผ ๋ณด์ฅํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ ์ ํ์ ์ฝ์ ์ ํ์ ๋ฐํํ์ฌ ๋ง์ ์ถ๊ฐ ๋ฉ์๋๊ฐ ์๋ Bluebird<T>
์ฒ๋ผ ๋ ์๊ฒฉํ๊ฒ ๋ง๋ค ์ ์์ต๋๋ค. ์ค๋ซ๋์ ES6 Promise ์ ํ์ ES6 ๊ธฐํธ๊ฐ ์ถ๊ฐ๋์๊ธฐ ๋๋ฌธ์ ๋ด Promise ์ค ์ด๋ ๊ฒ๋ ํ ๋นํ ์ ์์์ต๋๋ค.
@blakeembrey ์ฌ์ฉํ์ฌ PromiseLike
PromiseLike๋ ์๊ธฐ ๋๋ฌธ์์ด ๊ฒฝ์ฐ์ ๋๋ต์ํ์ง ์์ต๋๋ค ๋ค์์ ํธํ๋์ง ์๋ ๋ฒ์ ์ด
: ๋ถํํ๊ฒ๋ ์ฝ์ typings ๋ ์ด์ ๋์ TS ๋ฒ์ 2์์ ์ด๋ฌํ typings ์๋๋ก ๋ณ๊ฒฝ https://github.com/Microsoft/TypeScript/blob/070aa83cc06b2974639bbefcde98e6e2fb5fe693/src/lib/es2015.promise.d.ts
์ด ๋ฌธ์ ๋ฅผ ๋ค์ ์ด ์ ์์ต๋๊น?
์ด์ ๋ํ ์ ๋ฐ์ดํธ๊ฐ ์์ต๋๊น?
@OliverJAsh @arg20 ๋ฌธ์ ์ ๋ํ ์์ฒด ์ฌํ ๊ฐ๋ฅํ ํ ์คํธ ์ฌ๋ก๋ฅผ ์ ๊ณตํ ์ ์์ต๋๊น?
@Strate ์ฌ๊ธฐ์ ๋ด ์ค๋ฅ๊ฐ ์์ต๋๋ค. typescript 2.0.3(lib.es6.d.ts) ๋ฐ @types/bluebird v3.0.33 ์ฌ์ฉ
error TS2345: Argument of type 'Bluebird<Db>' is not assignable to parameter of type 'Promise
<Db>'.
Types of property 'then' are incompatible.
Type '{ <U1, U2>(onFulfill: (value: Db) => U1 | Thenable<U1>, onReject: (error: any) => U2 | Thenable<U...' is
not assignable to type '{ <TResult1, TResult2>(onfulfilled: (value: Db) => TResult1 | PromiseLike<TResult1>, onre
jected: ...'.
Type 'Bluebird<any>' is not assignable to type 'Promise<any>'.
Types of property 'then' are incompatible.
Type '{ <U1, U2>(onFulfill: (value: any) => U1 | Thenable<U1>, onReject: (error: any) => U2 | Thenable<.
..' is not assignable to type '{ <TResult1, TResult2>(onfulfilled: (value: any) => TResult1 | PromiseLike<TResult1
>, onrejected:...'.
Type 'Bluebird<any>' is not assignable to type 'Promise<any>'.
Bluebird Promise๋ฅผ ES6 Promise๋ก ์บ์คํ
ํ๋ ค๊ณ ํ๋ฉด ๋ค์์ด ๋ฐ์ํฉ๋๋ค( bluebirdPromise as Promise<Db>
).
error TS2352: Type 'Bluebird<Db>' cannot be converted to type 'Promise<Db>'.
Types of property 'then' are incompatible.
Type '{ <U1, U2>(onFulfill: (value: Db) => U1 | Thenable<U1>, onReject: (error: any) => U2 | Thenable<U...' is not comparable to type '{ <TResult1, TResult2>(onfulfilled: (value: Db) => TResult1 | PromiseLike<TResult1>, onrejected: ...'.
Type 'Bluebird<any>' is not comparable to type 'Promise<any>'.
Property '[Symbol.toStringTag]' is missing in type 'Bluebird<any>'.
# 10831์์ ์ ์ํ๋๋ก ์ด๊ฒ์ ์ถ๊ฐํ๋ฉด ์ ์๊ฒ ํจ๊ณผ์ ์ด์์ต๋๋ค.
readonly [Symbol.toStringTag]: 'Promise';
๋ํ ES6 Promise๋ก ๋ณํํ๋ฉด ํธ๋ฆญ์ ์ํํ์ต๋๋ค.
return new Promise.resolve(bluebirdPromise)
@jmendiara #10831์ ์ธ๊ธ๋ ๊ฒ์ฒ๋ผ ์ค์ ๋ก bluebird์๋ readonly [Symbol.toStringTag]
๊ฐ ์์ผ๋ฏ๋ก ์ด๊ฒ์ bluebird.d.ts์ ์ถ๊ฐํ๋ ๊ฒ์ ํ์คํ ์๋ชป๋ ๊ฒ์
๋๋ค. ํ์ดํ์ ์ค์ ์ธ๊ณ๋ฅผ ๋ํ๋ด์ผ ํฉ๋๋ค.
Promise ํ์ค์ด readonly [Symbol.toStringTag]
์๊ตฌํ๋ค๋ฉด, ๊ทธ๊ฒ์ bluebird ์์ฒด์ bluebird.d.ts์๋ ์ถ๊ฐ๋์ด์ผ ํฉ๋๋ค. ๋ธ๋ฃจ๋ฒ๋์ ๋ค์ดํฐ๋ธ ํ๋ผ๋ฏธ์ค ๊ฐ์ ๋ณํ์ ํ์คํ ์ฌ์ฉํด์ผ ํ๋ ๊ฒ ๊ฐ์ต๋๋ค(์ ๋ง ์ง์ฆ๋๋ค์).
์ฐธ๊ณ ๋ก new
ํค์๋ ์์ด Promise.resolve
๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
bluebird์ ์ฝ์์ ํ์ค ์ฝ์์ ํ ๋นํ ์ ์์ ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ ๊ฒฝ์ฐ์๋ bluebird๋ฅผ Promise.resolve
๋ก ํ์ค์ผ๋ก ์บ์คํ
ํ๋ ๊ฒ์ ๋ถ๊ฐ๋ฅํฉ๋๋ค. ์๋ํ๋ฉด ๊ทธ๊ฒ์ ์ 3์ ๊ฐ์ฒด์ ๊น์์ด ์๊ธฐ ๋๋ฌธ์
๋๋ค. ๋ฐ๋ผ์ ๋๋๋ก ๋ณํ ์์ด ํ์ค์ ํ ๋นํ ์ ์๋ค๋ bluebird์ ์ฝ์์ ๊ฐ๋ ๊ฒ์ด ํฉ๋ฆฌ์ ์
๋๋ค.
bluebird์ ๋ฆฌํฌ์งํ ๋ฆฌ์ ๊ธฐ๋ฅ ์์ฒญ์ ์์ฑํ์ฌ bluebird์ ์ธ์คํด์ค์ Symbol.toStringTag
๋ฅผ ์ถ๊ฐํ์ต๋๋ค.
์ด์ ๋ํ ์ ๋ฐ์ดํธ๊ฐ ์์ต๋๊น?
์ด ์ค๋ ๋๋ฅผ ์ฐพ์์ ๊ธฐ์ฉ๋๋ค. ๋ด๊ฐ ๋ฏธ์ณค๋ค๊ณ ์๊ฐํ๋ค. ์ด ๋ฌธ์ ์ ๋ํ ์์ ์ฌํญ์ ๋ณด๊ณ ์ถ์ต๋๋ค. ๋๋ SO ์ ๋ํ ๋ด ๋ฌธ์ ์ธ๋ถ ์ฌํญ์ ์ค๋ช ํ์ต๋๋ค.
@types/bluebird 3.5.3 ๋ฐ TypeScript 2.2.2์์ ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.
@silentorb @types/bluebird-global
์ ํ ์ ์๋ฅผ ์ฌ์ฉํ ๋ค์ ๋ด ์ฝ๋ ์๋จ์ ๋ค์์ ์ถ๊ฐํ์ฌ ์ ์ญ ์ฝ์ ์ ์(ES2015 ํ๋ซํผ์ ๋์์ผ๋ก ํ๋ ๊ฒฝ์ฐ ๊ฐ๊ฒ ๋จ)๋ฅผ ์ฌ์ ์ํ์ฌ ์ด ์์
์ ์ํํ์ต๋๋ค. ์คํ ์ง์
์ :
import * as Promise from 'bluebird';
global.Promise = require('bluebird');
์์ ๋ด์ฉ์ ๋ ธ๋ ํ๊ฒฝ์์ ์๋ํฉ๋๋ค(์ ๋ 6.10.x๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค). ์นํฉ ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ _expose-loader_์ ๊ฐ์ ๊ฒ์ ์ฌ์ฉํด์ผ ํ ์๋ ์์ต๋๋ค.
@ksnyde : ์ด์ ์ @types/bluebird-global
์ฌ์ฉํด ๋ณด์๊ณ ์ฌ๋ฌ ๊ฐ์ ๋๋ฝ๋ Promise ์ธ๋ถ ์ ๋ณด๋ฅผ ๋ฐ๊ฒฌํ์ต๋๋ค. @types/bluebird-global
ํจ์น๋ฅผ ๊ณ ๋ คํ์ง๋ง @types/bluebird
์๋ํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
@silentorb ํต์ฌ์ ์ ์ญ Promise ์ฐธ์กฐ๋ฅผ ์ฌ์ ์ํ๋ ๊ฒ์ ๋๋ค. ๋๋ฅผ ์ํด ๋ฌธ์ ์์ด ์๋ํฉ๋๋ค. ์ฆ, ๊ธฐ๋ณธ์ ์ผ๋ก ์๋ํ๋ฉด ํ์คํ ์ข๊ฒ ์ง๋ง ์ด ์๋ฃจ์ ์ผ๋ก ๊ธฐ๋ค๋ฆด ํ์๊ฐ ์์ต๋๋ค.
์ด์ ๋ํ ์ง์ ์ด ์์ต๋๊น?
๋๋ ๋ํ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค. ๋ค์๊ณผ ๊ฐ์ ์ค๋ฅ๋ก ์์ฝ๋ฉ๋๋ค.
type Promise<any> is not assignable to Bluebird<any>
๋งค์ฐ ์ค๋ง์ค๋ฝ์ต๋๋ค. ์ด๊ฒ์ ๋ํ sequelize
์ ๊ฐ์ ๋ค๋ฅธ ํ์ดํ ํจํค์ง์ ์ฌ์ฉ๋ฒ์ ๊นจ๋จ๋ฆฝ๋๋ค.
export interface MissionModel extends Sequelize.Model<MissionInstance, MissionAttributes. {
create(missionAttributes: MissionAttributes, opsions?: Sequelize.CreateOptions): Promise<MissionInstance>;
}
MissionModel
Promise
๋ฅผ * from "bluebird"
๋ก ๊ฐ์ ธ์ค์ง ์์ผ๋ฉด MissionModel
์ ๋ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
src\server\models\mission.ts(3,18): error TS2430: Interface 'MissionModel' incorrectly extends interface 'Model<MissionInstance, MissionAttributes>'.
Types of property 'create' are incompatible.
Type '(MissionAttributes: MissionAttributes, option?: CreateOptions | undefined) => Promise<MissionInst...' is not assignable to type '(values?: MissionAttributes | undefined, options?: CreateOptions | undefined) => Bluebird<Mission...'.
Type 'Promise<MissionInstance>' is not assignable to type 'Bluebird<MissionInstance>'.
Types of property 'then' are incompatible.
Type '<TResult1 = MissionInstance, TResult2 = never>(onfulfilled?: ((value: MissionInstance) => TResult...' is not assignable to type '{ <U>(onFulfill?: ((value: MissionInstance) => U | PromiseLike<U>) | undefined, onReject?: ((erro...'.
Type 'Promise<any>' is not assignable to type 'Bluebird<any>'.
@Strate ๋ฌธ์ ๋ฅผ ๋ค์ ์ด์ด ์ฃผ์๊ฒ ์ต๋๊น?
๋ค์ ์๊ฐํด๋ณด๋ฉด, ๋๋ ์๋กญ๊ณ ๋ ํ์ ์ด ๋๋ ๊ฒ์ ์ ์ถํ ๊ฒ์
๋๋ค.
๋๋ ์ด๋ฐ ์ข ๋ฅ์ ํ์ดํ์คํฌ๋ฆฝํธ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์๊ฐ์ ๋ญ๋นํ๋ ๊ฒ์ ์ ๋ง ์ซ์ดํฉ๋๋ค. ์ฝ๋๊ฐ ๋งค์ฐ ๋ช ํํ๊ธฐ ๋๋ฌธ์ tsc๋ฅผ ์ ๋ฌํ๋ ค๋ฉด ๋ ๋ง์ ์ถ๊ฐ ์์ ์ ์ํํด์ผ ํฉ๋๋ค. ๋ด๊ฐ ์์ ํ๋ ์ฌ์ด ๋ฐฉ๋ฒ์ ๋ชจ๋ ์ ํ์ ์์ ๋ณ์๋ฅผ ๋ง๋๋ ๊ฒ์ ๋๋ค. ๊ทธ๋ฐ ๋ค์ ๋์ Promise๋ก ๋ณํํ์ญ์์ค. ์ ๊ฐ์:
'''
const p: ๋ชจ๋ = getPromise();
๋ฐํ
'''
@flyingsky (et. al.) ์ฐ์ Bluebird Promise๊ฐ ๊ธฐ๋ณธ ๊ตฌํ์ ์กด์ฌํ์ง ์๋ ํ์ฅ์ ์ ๊ณตํ๊ธฐ ๋๋ฌธ์ ๊ธฐ๋ณธ Promise๋ฅผ Bluebird์ ์ง์ ํ ๋นํ๋ ๊ฒ์ ๊ฒฐ์ฝ ๋ถ๊ฐ๋ฅํ๋ค๋ ์ ์ ๋ค์ ํ ๋ฒ ๋ชจ๋ ์ฌ๋์๊ฒ ์๊ธฐ์ํค๊ณ ์ถ์ต๋๋ค.
๋ฐ๋ฉด์ ๊ธฐ๋ณธ ์ฝ์์ Bluebird ์ฝ์์ ํ ๋นํ๋ ๊ฒ์ ๊ฐ๋ฅํด์ผ ํ๋ฉฐ ๋น์ฐํ ๊ทธ๋์ผ ํฉ๋๋ค. ๊ทธ๋ฌ๋ ์ฌ๊ธฐ ์๋ ๋ง์ ์ฌ๋๋ค์ ์ด๊ฒ์ด ์ง๊ธ ๋น์ฅ์ ํจ๊ณผ๊ฐ ์์ด์ผ ํ๋ค๋ ์ธ์์ ๋ฐ๊ณ ์์ต๋๋ค. ์ด๋ ํ์คํ ์ฌ์ค์ด ์๋๋๋ค.
๊ทธ ์ด์ ๋ Bluebird๊ฐ ์ผ๋ฐ์ ์ผ๋ก ์๋ ค์ง ๋ชจ๋ ๊ธฐ๋ฅ์ ๊ธฐ๋ณธ ํธํ ๋ฐฉ์์ผ๋ก ๋
ธ์ถํ์ง๋ง ํน์ ํ๋ ํ๋๋ฅผ _๋
ธ์ถํ์ง ์๊ธฐ ๋๋ฌธ์
๋๋ค. [Symbol.toStringTag]
ํ๋๋ "promise"
์ฌ์ผ ํฉ๋๋ค. ์ฌ๊ธฐ๋ฅผ ์ฐธ์กฐํ์ญ์์ค: https://github.com/petkaantonov/bluebird/issues/1277. ์ด๋ก ์ธํด Bluebird๋ ๊ธฐ๋ณธ ์ฝ์๊ณผ ํธํ๋์ง ์๋ ๊ฒ์ผ๋ก ์๊ฒฉํ๊ฒ ํ์๋ฉ๋๋ค. ์...
const p: any = getPromise();
return <Promise>p;
์ด๊ฒ์ ๊ธฐ์ ์ ์ผ๋ก ์์ ํ์ง ์๊ณ ์ฌ๋ฐ๋ฅด์ง ์์ ์ ํ์ ๋๋ค.
@types/bluebird-global
ํจ์น๋ฅผ ๊ณ ๋ คํ์ง๋ง@types/bluebird
์๋ํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
bluebird-global
๋ bluebird
์์ ํ ๋ค๋ฅธ ์ฌ์ฉ ์ฌ๋ก๋ฅผ ์ ๊ณตํฉ๋๋ค. Promise
๋ณ์๋ฅผ ๋ฎ์ด์ฐ๋ ๋งค์ฐ ์ํํ ์ ํ์ ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์ ์กด์ฌํฉ๋๋ค Bluebird
. (๋จ์ํ ๋ฎ์ด์ด๋ค๊ณ ํด์ ์์กดํ๋ ๋ชจ๋ ํจํค์ง๊ฐ ๋ค์ดํฐ๋ธ ํ๋ผ๋ฏธ์ค๋ฅผ ๊ณ์ ์ฌ์ฉํ์ง ์๋๋ค๋ ์๋ฏธ๋ ์๋๊ธฐ ๋๋ฌธ์ ์์ ํ์ง ์์ต๋๋ค.)
์ด ๋ฌธ์ ์ ์งํ ์ํฉ์ ๋ณด๊ณ ์ถ์ ์ฌ๋์ด ์์ผ๋ฉด ์ด๋ฏธ ์ธ๊ธํ Bluebird ๋ฌธ์ ์ ๋ํ PR์ ์ฌ๋ ๊ฒ์ด ์ข์ต๋๋ค. https://github.com/petkaantonov/bluebird/issues/1277
์ด ๋ฌธ์ ์ ์งํ ์ํฉ์ ๋ณด๊ณ ์ถ์ ์ฌ๋์ด ์์ผ๋ฉด ์ด๋ฏธ ์ธ๊ธํ Bluebird ๋ฌธ์ ์ ๋ํ PR์ ์ฌ๋ ๊ฒ์ด ์ข์ต๋๋ค. petkaantonov/bluebird#1277
์ด PR์ด ์์ฑ๋ ๊ฒ ๊ฐ์ต๋๋ค: https://github.com/petkaantonov/bluebird/pull/1421
@ksnyde โ ๊ทํ์ @types/bluebird-global
์ ์์ด ์ ์๊ฒ ํจ๊ณผ์ ์ด๋ฉฐ ์ฝ๊ฐ ์์ ๋์์ต๋๋ค.
import * as Promise from 'bluebird'
global.Promise = Promise
๊ทธ๋ ์ง ์์ผ๋ฉด ๋ด๊ฐ ์ป์ error TS6133: 'Promise' is declared but its value is never read.
์์๋๋ tsconfig.json
์ "noUnusedLocals": true
.
๊ฐ์ฌํฉ๋๋ค.
bluebird-global
์์ง๋ง ์ฌ์ ํ ๋ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
'Bluebird ์ ํ'์ '[Symbol.toStringTag]' ์์ฑ์ด ์์ต๋๋ค.
'
์ด ์ค์ ์ถ๊ฐํ๋ฉด ๋ฌธ์ ๊ฐ ์์ ๋ฉ๋๋ค. https://github.com/DefinitelyTyped/DefinitelyTyped/pull/10831/files
๋ธ๋ฃจ๋ฒ๋์ ํ์ดํ์ ์์ ํ์ง ์๊ณ ๋ก์ปฌ์์ ์์ ํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
+1
@gdpaulmil ๊ฑด์ค์ ์ธ ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค!
Bluebird์ ์ํฉ์ ์ดํด๋ณด๊ฒ ๋์์ต๋๋ค.
https://github.com/petkaantonov/bluebird/pull/1421 ์ด 11์ผ ์ ์ ๋ณํฉ๋์ด ๋ง์นจ๋ด Symbol.toStringTag
๋ํ ์ง์์ ์ถ๊ฐํ์ต๋๋ค! ๐
์ด๋ ๋ค์ #10831์ ๋ค์ ์ ์ถํ์ฌ ์ด ๋ฌธ์ ๋ฅผ ์ฆ์ ํด๊ฒฐํ ์ ์์์ ์๋ฏธํฉ๋๋ค. "Promise"
๋ฅผ "Object"
๋ก ๋ฐ๊พธ๋ฉด ๋ฉ๋๋ค. ์์งํ ๋ฐ๋ก ๋ฆฌ๋ทฐํ๊ฒ ์ต๋๋ค. ๐
@lhecker , ์ด ๋ชจ๋ ๊ฒ์ ์ ๋ฆฌํ๊ธฐ ์ํด #35353์ ๋ง๋ค์์ต๋๋ค!
์ด ๋ฌธ์ ๊ฐ @types/bluebird
v3.5.27์์ ์์ ๋์์์ ์๋ ค๋๋ฆฝ๋๋ค.
์ด์ ์ด ๋ชจ๋ Bluebirds๋ฅผ ์ด ๋ชจ๋ Promise์ ํ ๋นํ๋ ๊ฒ์ ์ฆ๊ธธ ์ ์์ต๋๋ค. ๐
ํ์ง๋ง ์ด๋ฅผ ์ํด์๋ TypeScript 3.2 ์ด์์ ์ฌ์ฉํด์ผ ํฉ๋๋ค. (#34805 ์ฐธ์กฐ)
์ถ์ : Bluebird PR์ ์ฒ๋ฆฌํด ์ฃผ์ @JoshuaKGoldberg ์๊ฒ ๋ค์ ํ ๋ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ๐๐
์ด๋ค:
import * as Promise from 'bluebird';
global.Promise = require('bluebird');
es2017์๋ ๊ณ์ ์ ์ฉ๋๋์?
์ด์ ๋ฒ์ ์ ์ข ์์ฑ์ผ๋ก ๊ฐ์ง๊ณ ์๊ณ ๋ฉ๋ชจ๋ฅผ ๋ฐ์ง ๋ชปํ ๋ค๋ฅธ ๋ชจ๋ ํจํค์ง๋ฅผ ์ ์ธํ๊ณ ... request-promise, knex,... ๋น์ ์ ์ด๋ฒ ์ ๋ฐ์ดํธ๋ก ๋ง์ ์ฝ๋๋ฅผ ๊นจ๋จ๋ ธ์ต๋๋ค. Typescript ์ปดํ์ผ๋ฌ๋ ๋ชจ๋ ๊ณณ์์ ๋ง๋ ์๋๋ ์ค๋ฅ๋ฅผ ๋์ง๊ณ ์์ต๋๋ค. Typescript 3.3, 3.4, 3.5...๋ ์ค์ํ์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค.
๋๊ตฐ๊ฐ์๊ฒ ๋์์ด๋๋ค๋ฉด ์์์ ์ธ๊ธํ๋ฏ์ด ์ ์ญ Promise ๊ฐ์ฒด๋ฅผ BB๋ก ๋ฐ๊พธ์ง ์๋ ๊ฒ์ด ๊ฐ์ฅ ์ฌ์ ์ต๋๋ค. ํ ๊ฐ์ง๊ฐ ๋ค๋ฅธ ๊ฒ๊ณผ ํธํ๋๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ง ์์์ต๋๋ค.
@jacklinton ์ํฅ์ ๋ฐ๋ ๋ชจ๋ ํจํค์ง๊ฐ "๋ฌด์๋ฏธํ ์ค๋ฅ๋ฅผ ๋์ง์ง" ์๊ณ ์ฌ์ ํ ์ฃผ์ด์ง TypeScript ๋ฒ์ ์ผ๋ก ๋น๋๋๋์ง ํ์ธํ๊ธฐ ์ํ ๋จ์ ํ
์คํธ๊ฐ ๋ง๋ จ๋์ด ์๋ค๋ ๊ฒ์ ์ด๋ฏธ ์๊ณ ๊ณ์ค ๊ฒ์
๋๋ค.
์๋ฅผ ๋ค์ด ๋ค์์ ์ต์ Bluebird ํ์ดํ์ผ๋ก ์์
ํ๋ ์์ฒญ ์ฝ์์ ๋ณด์ฌ์ฃผ๋ ํ๋ก์ ํธ์
๋๋ค. https://github.com/lhecker/request-promise-sample
๊ทํ์ ๋ฌธ์ ๋ฅผ ์ฌํํ ์ ์์ผ๋ฏ๋ก ๊ทํ๊ฐ ๋ณด๊ณ ์๋ ๋ฌธ์ ๋ฅผ ๋ณด์ฌ์ฃผ๋ ์ต์ํ์ ์๋ฅผ ์ ๊ณตํ ์ ์๋ค๋ฉด ์ ๋ง ์ข์ ๊ฒ์
๋๋ค.
์ด๋์๋ถํฐ ์์ํด์ผ ํ ์ง ์๊ธฐ ์ด๋ ต์ง๋ง ๋ค๋ฅธ ๋ชจ๋ ํจํค์ง๋ ์ต์ ์ํ์
๋๋ค.
Error:(19, 3) TS2741: Property '[Symbol.toStringTag]' is missing in type 'Bluebird<string[]>' but required in type 'Bluebird<string[]>'.
@types/bluebird๋ฅผ ์ ๊ฑฐํ๋ฉด ์ด๋ฌํ ์ค๋ฅ๊ฐ ์ฌ๋ผ์ง๋๋ค. ๋ด๊ฐ ๊ฐ์ง ์๊ฐ์ผ๋ก ํ ์ ์๋ ์ ์ผํ ์ถ์ธก์ ์ด๋ฌํ ์ ํ์ ํ์๋ก ํ๋ ๋ค๋ฅธ ๋ชจ๋ ํจํค์ง๊ฐ ์์ง ๋ฐ๋ผ์ก์ง ๋ชปํ๋ค๋ ๊ฒ์
๋๋ค. Knex๊ฐ ๋ฒ์ธ์ผ ๊ฐ๋ฅ์ฑ์ด ์๋ ๊ฒ์ผ๋ก ์์ฌ๋์ง๋ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ์ด ํจํค์ง์ ์ด์ ๋ฒ์ ์ ๋ํ ์์ฒด ์ข
์์ฑ์ ๊ฐ์ ธ์ต๋๋ค.
์ด ์ค๋ฅ๋ @types/bluebird
์ ๋ ๊ฐ์ง ๋ฒ์ ์ด ์ค์น๋ ๊ฒ์ฒ๋ผ ๋ค๋ฆฝ๋๋ค. ๋น์ ์ ๋น์ ์ด ๊ทธ๋ค ์ค ํ๋๋ง ๊ฐ์ง ์ ์๋๋ก ๊ทธ ๋๋ฌด๋ฅผ ํํํ๊ฒ ํ ์ ์๋์ง ํ์ธํ๊ณ ์๋ํด์ผ ํฉ๋๋ค.
knex 0.17.3์ @types/bluebird
ํ์ดํ btw์ ์ต์ 3.5.27 ๋ฒ์ ์ ๋ฐ๋ผ ๋ค๋ฆ
๋๋ค. ์ต์ ๋ฒ์ ์ knex๊ฐ ์์ผ๋ฉด ์ค์ ๋ก ์๋ํด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
@types/bluebird
์ ๋ ๋ฒ์งธ ์ฌ๋ณธ๋ ๋ง์ฐฌ๊ฐ์ง์
๋๋ค. ๋ํ 3.5.27์ด์ด์ผ ํฉ๋๋ค.
์๋ต ํด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค
@lhecker ์์ฒญ-์ฝ์-์ํ ์ด ์ฌ๋ผ์ง ๊ฒ ๊ฐ์์ ๋ค์ ๊ฒ์ํด ์ฃผ์๊ฒ ์ต๋๊น? ๐ข
@VictorioBerra ์ ํธ๋ฆญ
import * as Promise from 'bluebird';
global.Promise = require('bluebird');
Node.js 12์์ ๋ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
global.Promise = ์ฝ์;
'typeof Bluebird' ์ ํ์๋ 'Function' ์ ํ์์ ๋ค์ ์์ฑ์ด ๋๋ฝ๋์์ต๋๋ค. ์ ์ฉ, ํธ์ถ, ๋ฐ์ธ๋ฉ, ๊ธธ์ด ๋ฐ ๊ธฐํ 4๊ฐ.
TypeScript v3.7.4, bluebird v3.7.2 ๋ฐ @types/bluebird-global v3.5.12๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
@bennyn ๋ ์ด์ ์ฝ๋๊ฐ ์์ต๋๋ค. ๋๋ ๋งค์ฐ ๋ฏธ์ ํด์. ์์ฒญ-์ฝ์ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ ํ ์ญ์ ํ์ต๋๋ค.
3.5.29์์ ์ต์ ๋ฒ์ ์ @types/bluebird
๋ฅผ ์ฌ์ฉํ๊ณ ์๋์ง ํ์ธํ์ธ์.
๋ชจ๋ bluebird, @types/bluebird-global ๋ฐ TypeScript์ ์ต์ ๋ฒ์ ์์ @bennyn ๊ณผ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
ํ์ฌ ๋ฒ์ ์ Bluebird 3.7.2 ๋ฐ TypeScript 3.6์์ ์คํ ๊ฐ๋ฅํ ์ ์ผํ ์ต์ ์ Bluebird ํ์ดํ์ ์ ํ ์ฌ์ฉํ์ง ์๋ ๊ฒ์ ๋๋ค.
์ฑ ์ง์ ์ ์์ ๋ค์ดํฐ๋ธ Promise ์์ฑ์๋ฅผ Bluebird๋ก ๋ฐ๊พธ๊ณ ๊ทธ ํ์ ๋ค์ดํฐ๋ธ Promise API๋ฅผ ์ฌ์ฉํ์ฌ Bluebird๋ฅผ ์ฌ์ฉํฉ๋๋ค.
import * as Bluebird from "bluebird";
global.Promise = Bluebird;
new Promise((resolve, reject) => {
// this is actually a Bluebird object
});
๋๋ ๊ฐ์ธ์ ์ผ๋ก ์์งํ ๋งํด์ ๋ํฌ๋ค์ด ๋ํฌ ์ชฝ์์ ๋ญ๊ฐ ์๋ชปํ๊ณ ์๋ค๊ณ ๋ฏฟ๋๋ค. ๐
๋๋ ๋น์ ์ด ์ด๋ป๊ฒ ์ ๋์ ์ผ๋ก 100% ํ์คํ ํ ์ ์๋์ง ๋ณด์ฌ์ฃผ๋ ์ต์ํ์ request-promise-sample
ํ๋ก์ ํธ ๋ฅผ ์ฌ๊ตฌ์ฑํ์ต๋๋ค.
Bluebird
์์ฑ์๋ฅผ global.Promise
ํ ๋นBluebird
ํด๋์ค ์ธ์คํด์ค๋ฅผ Promise
์ธํฐํ์ด์ค์ ํ ๋นํฉ๋๋ค (์ด๊ฒ์ด ์ด ๋ฌธ์ ์ ๋ํ ๊ฒ์
๋๋ค)._ํ์ง๋ง ์ด ๋ฌธ์ ๋ ์ข
๋ฃ๋์์ผ๋ฉฐ ์ฃผ์ ์์ ๋ฒ์ด๋ ํ ๋ก ์ ๊ณ์ํ๋ ๋ฐ ์ฌ์ฉํด์๋ ์ ๋ฉ๋๋ค._
์ด ํฐ์ผ์ ES6/๋ค์ดํฐ๋ธ ํ๋ผ๋ฏธ์ค์ ํ ๋นํ ์ ์๋ Bluebird ํ๋ผ๋ฏธ์ค์ ๊ดํ ๊ฒ์ด๋ฏ๋ก ์์ ๋
ผ์๋ ์ฃผ์ ์์ ๋ฒ์ด๋ฌ์ต๋๋ค. ๊ทธ๋ฌ๋ ์์ ํ์๋ ๊ฒ์ฒ๋ผ ์ด ๋ฌธ์ ๋ ์ค๋ซ๋์ ์์ ๋์์ต๋๋ค.
Bluebird์์ @types/[email protected]
๋ฅผ ์ฌ์ฉํ๋ ๋ฐ ๋ฌธ์ ๊ฐ ์๋ ๊ฒฝ์ฐ ๋์ https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42084 ๋ฅผ ์ฐธ์กฐ
@lhecker
๋ต๋ณ ๊ฐ์ฌํฉ๋๋ค. ๊ทํ์ ํ๋ก์ ํธ๋ฅผ ์๋ํ์ง๋ง ์๋ํ์ง ์์ต๋๋ค.
@types/[email protected]
์ค์น๋ ๋์์ด ๋์ง ์์ต๋๋ค.
์์ ๋ ํ๋ก์ ํธ๋ ์ฌ๊ธฐ์์ ์ฐพ์ ์ ์์ต๋๋ค:
https://github.com/chebum/request-promise-sample
@chebum ์์ ๊ทํ์ ์๊ฒฌ์ Bluebird<T>
๋ฐํํ๋ ๋น๋๊ธฐ ํจ์๋ฅผ ์
๋ ฅํ๋ ค๊ณ ํ๋ค๋ ๊ฒ์ ๋ถ๋ช
ํ ํ์ง ์์์ต๋๋ค. ๊ทธ๋ฐ ๊ฒฝ์ฐ์๋ ๋ถํํ๋ ์ด๊ฒ์ด ๋ถ๊ฐ๋ฅํ๋ค๊ณ ์ด๋ฏธ ๋งํ ์ ์์์ต๋๋ค. ์ปดํ์ผ๋ฌ์ ์ถ๋ ฅ์์ โโ๋ณผ ์ ์๋ฏ์ด ๋น๋๊ธฐ ํจ์์์ Promise<T>
์ ํ์ _๋ฐํํด์ผ ํฉ๋๋ค.
ํ์ ์์ ์ฑ์ ์ฝ๊ฐ ํฌ๊ธฐํ๊ณ ์ถ๋ค๋ฉด ๋ค์์ ์ํํ ์ ์์ต๋๋ค.
@types/bluebird-global
๋ฅผ ์ข
์์ฑ์ผ๋ก ์ถ๊ฐwindow.Promise = Bluebird as any;
async function testFn(): Promise<void>
Promise<T>
์ ํ์ ์ด์ Bluebird<T>
์ ๊ฑฐ์ ๋์ผํ๋ฉฐ ๋ชจ๋ ์ค์ํ Bluebird ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.Symbol.species
์ค๋ฅ ๋ฑ์ ๋ฐ๊ฒฌํ๋ค๋ฉด ์ด ํฐ์ผ์ _์ฌ์ฉํ์ง ๋ง๊ณ _ #42084๋ฅผ ์ฌ์ฉํ์ธ์.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@silentorb
@types/bluebird-global
์ ํ ์ ์๋ฅผ ์ฌ์ฉํ ๋ค์ ๋ด ์ฝ๋ ์๋จ์ ๋ค์์ ์ถ๊ฐํ์ฌ ์ ์ญ ์ฝ์ ์ ์(ES2015 ํ๋ซํผ์ ๋์์ผ๋ก ํ๋ ๊ฒฝ์ฐ ๊ฐ๊ฒ ๋จ)๋ฅผ ์ฌ์ ์ํ์ฌ ์ด ์์ ์ ์ํํ์ต๋๋ค. ์คํ ์ง์ ์ :์์ ๋ด์ฉ์ ๋ ธ๋ ํ๊ฒฝ์์ ์๋ํฉ๋๋ค(์ ๋ 6.10.x๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค). ์นํฉ ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ _expose-loader_์ ๊ฐ์ ๊ฒ์ ์ฌ์ฉํด์ผ ํ ์๋ ์์ต๋๋ค.