我正试图包装这个简单的API:https://github.com/github-tools/github,仅用于学习目的。因此,我创建了以下外部类:
import { Document, Schema, Model, model} from "mongoose";
export interface IApplication {
id: number;
name: string;
virtualProperty: string;
}
interface IApplicationModel extends Document, IApplication {
id: number;
}
let ApplicationSchema: Schema = new Schema({
id: { type: Number, required: true, index: true, unique: true},
name: { type: String, required: true, trim: true },
});
ApplicationSchema.virtual('virtualProperty').get(function (this: IApplicationModel) {
return `${this.id}-${this.name}/`;
});
export const IApplication: Model<IApplicationModel> = model<IApplicationModel>("Application", ApplicationSchema);
在一个简单的KotlinJS项目中,一切正常,但是当我尝试在使用Create React Kotlin App创建的项目中使用时,出现以下错误:
package index
import com.github.jesty.githubapi.Result
import com.github.jesty.githubapi.User
import kotlin.js.Promise
external class GitHub(user: User) {
fun getUser(): GHUser
}
external class GHUser {
fun listStarredRepos(): Promise<Result>
}
答案 0 :(得分:0)
刚刚解决,我需要使用@JsModule(“ github-api”)注释外部类:
package com.github.jesty.githubapi
import kotlin.js.Promise
@JsModule("github-api")
external class GitHub(user: User) {
fun getUser(): GHUser
}
@JsModule("github-api")
external class GHUser {
fun listStarredRepos(): Promise<Result>
}