ts-morph#PropertySignature TypeScript Examples
The following examples show how to use
ts-morph#PropertySignature.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts From tarojs-router-next with MIT License | 6 votes |
export function extractType(options: { name: string; declaration: TypeAliasDeclaration; checker: TypeChecker }) {
const { name, declaration, checker } = options
if (!TypeAliasDeclaration.is(declaration.getKind())) throw Error(`${name} 应该导出类型定义`)
let optional = true
for (const p of declaration.getType().getProperties()) {
const ds = p.getDeclarations() as PropertySignature[]
if (ds.length > 1) throw Error('未知错误')
if (!ds[0].getQuestionTokenNode()) {
optional = false
break
}
}
const text = checker.getTypeText(declaration.getType(), declaration.getTypeNode(), ts.TypeFormatFlags.InTypeAlias)
return {
text,
optional,
name,
}
}