Microsoft/TypeScript

Language Service: TypeParameter.constraint is lazily calculated, but does not have an accessor function

已關閉

#5,689 建立於 2015年11月16日

 (4 則留言) (0 個反應) (0 位負責人)TypeScript (13,395 個分叉)batch import
BugDomain: APIHelp Wanted

倉庫指標

星標
 (108,860 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Because of this, I have to go through this awkward motion every time:

function getConstraint( type: ts.TypeParameter ) {
  // This call will cause the typechecker to resolve properties, as well as a bunch of other information
  // about the type (such as generic constraints), but we don't actually need its result right now.
  type.getProperties(); 

  return type.constraint;
}

For some members (such as "properties" - above), there is an accessor function, which I can use to be sure the data is up to date. Another category of members don't need an accessor function, because they are calculated eagerly, and so are "always there".

But there is this third category of members, which fall through the gap. One example is TypeParameter.constraint. Another is InterfaceTypeWithDeclaredMembers.declaredProperties. There are probably more, but I haven't come across them yet.

貢獻者指南