You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Compiler API - Type parameter constraint and default always undefined #20137
consttype= ...;// get type of VariableDeclarationconstsignature=type.getCallSignatures()[0];consttypeParam=signature.getTypeParameters()[0];typeParam.constraint;// undefinedtypeParam.default;// undefined
Expected behavior: A string type will be returned for both.
Actual behavior: Always returns undefined.
typescript.d.ts says the following:
interfaceTypeParameterextendsTypeVariable{/** Retrieve using getConstraintFromTypeParameter */constraint: Type;default?: Type;}
Problems
Both properties are always undefined (from why I've tried).
getConstraintFromTypeParameter does not exist anywhere in the compiler api.
constraint: Type should have a question token.
Workaround
Get type's symbol.
Get symbol's type parameter declaration.
Get type via type checker from type parameter declaration's constraint and default nodes (if they exist).
changed the title [-]Compiler API - Signature constraint and default always undefined[/-][+]Compiler API - Type parameter constraint and default always undefined[/+]on Nov 20, 2017
Activity
mhegazy commentedon Nov 20, 2017
We need to make these internal and instead expose
getDefaultandgetConstrainton aTypeObject.[-]Compiler API - Signature constraint and default always undefined[/-][+]Compiler API - Type parameter constraint and default always undefined[/+]dsherret commentedon Nov 29, 2017
Thanks guys!