ts-morph#TypeAliasDeclaration TypeScript Examples

The following examples show how to use ts-morph#TypeAliasDeclaration. 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: extract-dom-types.ts    From SimpleWebAuthn with MIT License 6 votes vote down vote up
unresolvedNodes = new Set<InterfaceDeclaration | TypeAliasDeclaration>(
  types.map(type => {
    const node = domSourceFile.getInterface(type) ?? domSourceFile.getTypeAlias(type);
    if (!node) {
      throw new Error(`${type} does not refer to an interface or type alias`);
    }
    return node;
  }),
)
Example #2
Source File: index.ts    From tarojs-router-next with MIT License 6 votes vote down vote up
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,
  }
}
Example #3
Source File: extract-dom-types.ts    From SimpleWebAuthn with MIT License 5 votes vote down vote up
resolvedNodes = new Set<InterfaceDeclaration | TypeAliasDeclaration>()