目录
添加js/ts扩展库
添加js扩展库
1.使用addExtraLib
filePath同名会覆盖
monaco.languages.typescript.javascriptDefaults.addExtraLib(`
/**
* @typedef Api
* @property {string} version
* @property {IFN} fn
*/
/**
* @typedef IFN
* @property {(...params: number)=>number} sum
* @property {(...params: any, separator: string) => string} join
*/
`, 'globalApi.js')
2.使用 setExtraLibs
filePath同名会覆盖
monaco.languages.typescript.javascriptDefaults.setExtraLibs([{
filePath: 'globalApi.js',
content: `
/**
* sum
* @param {number[]} params
*/
function sum(...params) {
return params.reduce((l, r) => l + r, 0)
}
const Api = {
version: '1.0.1',
fn: {
sum
}
}
`
}])
添加ts扩展库
1.使用addExtraLib
monaco.languages.typescript.typescriptDefaults.addExtraLib(`
function sum(...params: number[]) {
return params.reduce((l, r) => l + r, 0)
}
const Api = {
version: '1.0.1',
fn: {
sum
}
}
`, 'globalApi.js')
2.使用setExtraLibs
monaco.languages.typescript.typescriptDefaults.setExtraLibs([{
content: `
interface Api {
version: string
fn: IFn
}
interface IFn {
sum: (...params: number[]) => number
}
`,
filePath: 'globalApi.js'
}])
标签:...,sum,number,js,编辑器,api,params,monaco
From: https://www.cnblogs.com/ibxk/p/15547065.html