반응형
유형 스크립트 확장 서드 파티 선언 파일
타사 선언 파일을 확장하려면 어떻게 해야 합니까?
예를 들어, 나는 확장하고 싶습니다.Context
@types/koa에서 필드를 추가합니다(resource
) 그것으로.
시도해 봤습니다.
// global.d.ts
declare namespace koa {
interface Context {
resource: any;
}
}
하지만 효과가 없습니다.
error TS2339: Property 'resource' does not exist on type 'Context'.
갱신하다
다음 오류가 발생하는 내 코드의 단순화된 버전:
import {Context} from 'koa';
import User from './Models/User';
class Controller {
async list(ctx: Context) {
ctx.resources = await User.findAndCountAll();
ctx.body = ctx.resources.rows;
ctx.set('X-Total-Count', ctx.resources.count.toString());
ctx.status = 200;
}
}
typescript v2.4
// tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"exclude": [
"node_modules"
]
}
import { Context } from "koa";
declare module "koa" {
interface Context {
resource: any;
}
}
언급URL : https://stackoverflow.com/questions/46493253/typescript-extend-third-party-declaration-files
반응형
'prosource' 카테고리의 다른 글
Oracle에서 count(1)와 count(*)의 차이 (0) | 2023.07.02 |
---|---|
웹 스트림과 Node.js 스트림 API의 차이점 (0) | 2023.07.02 |
Pandas DataFrame에 대한 행을 열 헤더로 변환합니다. (0) | 2023.07.02 |
봇코어의 NoSuchKey 예외를 캡처하는 방법은 무엇입니까? (0) | 2023.07.02 |
Git의 작업 디렉터리에 변경 사항을 보관하는 동안 변경 사항을 저장합니다. (0) | 2023.07.02 |