슬러그 모듈에 대한 공식 d.ts 파일이 없기 때문에 모든 종류의 오류가 발생합니다.
먼저 모듈을 가져 오는 파일이 있습니다.
import * as slug from "slug" // Had to create a custom d.ts empty file to avoid compile error as no official definition file existed
let slugify = function (data: string): string {
let slugified: string = slug('ééé aaa ooo') // error here
return slugified
}
export default slugify
그리고 다음은 컴파일러에서 가져 오기 오류 메시지를 방지하기 위해 만들어야하는 빈 d.ts 파일입니다.
declare module "slug" {
}
새로운 문제는 slug ( 'ééé aaa ooo')에 있습니다.
error TS2349: Cannot invoke an expression whose type lacks a call signature.
이 문제를 어떻게 해결할 수 있습니까? d.ts 파일에 "가짜"콘텐츠를 추가해야합니까?
컴파일러는 slug의 작동 방식을 알아야하며 정의 파일의 모듈에서 slug가 JavaScript에서 어떻게 보이는지 나타내는 함수의 선언을 내 보내어 알려줄 수 있습니다.
한 가지 방법은 다음과 같습니다.
declare module "slug" {
interface SlugOptions {
lower?: boolean;
// ...add the other options here...
}
function slug(val: string, optionsOrReplacement?: SlugOptions | string): string;
export = slug;
}
나는이 라이브러리를 가져올 수있는 유일한 방법은 사용하는 것입니다 생각 require
이 있기 때문에 사용하지 않는 JS 코드에서 이름 / 기본 내보내기 :
import slug = require("slug");
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다