MCPcopy Create free account
hub / github.com/angular/components / getInjectionType

Function getInjectionType

tools/tslint-rules/lightweightTokensRule.ts:145–162  ·  view source on GitHub ↗

Gets an identifier that represents the given type node's resolved value.

(type: ts.TypeNode)

Source from the content-addressed store, hash-verified

143
144/** Gets an identifier that represents the given type node's resolved value. */
145function getInjectionType(type: ts.TypeNode): ts.Identifier | null {
146 // Unwraps union types with `null`. This is supported in Angular when
147 // `@Optional` is used. The `null` union type is ignored.
148 if (ts.isUnionTypeNode(type)) {
149 const nonNullTypes = type.types.filter(t => t.kind !== ts.SyntaxKind.NullKeyword);
150 return nonNullTypes.length === 1 ? getInjectionType(nonNullTypes[0]) : null;
151 }
152 if (!ts.isTypeReferenceNode(type)) {
153 return null;
154 }
155 const unwrapEntityName = (n: ts.EntityName): ts.Identifier => {
156 if (ts.isQualifiedName(n)) {
157 return unwrapEntityName(n.right);
158 }
159 return n;
160 };
161 return unwrapEntityName(type.typeName);
162}
163
164/**
165 * Analyzes the decorators of the given parameter. Returns whether it has

Callers 1

Calls 2

unwrapEntityNameFunction · 0.85
filterMethod · 0.45

Tested by

no test coverage detected