Skip to content

Commit a88be7c

Browse files
author
Arthur Ozga
committed
consolidate SignatureParts
1 parent 41e511e commit a88be7c

File tree

3 files changed

+15
-38
lines changed

3 files changed

+15
-38
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ namespace ts {
107107
getReturnTypeOfSignature,
108108
getNonNullableType,
109109
createTypeNode,
110-
createTypeParameterDeclarationFromType,
111110
createIndexSignatureFromIndexInfo,
112-
createParameterDeclarationFromSymbol,
111+
createSignatureParts,
113112
getSymbolsInScope: (location, meaning) => {
114113
location = getParseTreeNode(location);
115114
return location ? getSymbolsInScope(location, meaning) : [];
@@ -2222,13 +2221,6 @@ namespace ts {
22222221
return parameterNode;
22232222
}
22242223

2225-
/* @internal */
2226-
type SignatureParts = {
2227-
typeParameters: TypeParameterDeclaration[] | undefined;
2228-
parameters: ParameterDeclaration[];
2229-
type: TypeNode;
2230-
}
2231-
22322224
// TODO: expose this, remove copy from helper, possibly don't expose createParameter/TypeParameter?
22332225
function createSignatureParts(signature: Signature): SignatureParts {
22342226
return {

src/compiler/types.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,14 +2468,12 @@ namespace ts {
24682468
/* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type;
24692469
getNonNullableType(type: Type): Type;
24702470

2471-
/** Note that the resulting type node cannot be checked. */
2471+
/** Note that the resulting nodes cannot be checked. */
24722472
createTypeNode(type: Type): TypeNode;
2473-
/** Note that the resulting type node cannot be checked. */
2474-
createTypeParameterDeclarationFromType(type: Type): TypeParameterDeclaration;
2475-
/** Note that the resulting type node cannot be checked. */
2476-
createIndexSignatureFromIndexInfo(indexInfo: IndexInfo, kind: IndexKind): IndexSignatureDeclaration
2477-
/** Note that the resulting type node cannot be checked. */
2478-
createParameterDeclarationFromSymbol(parameterSymbol: Symbol): ParameterDeclaration;
2473+
/** Note that the resulting nodes cannot be checked. */
2474+
createIndexSignatureFromIndexInfo(indexInfo: IndexInfo, kind: IndexKind): IndexSignatureDeclaration;
2475+
/** Note that the resulting nodes cannot be checked. */
2476+
createSignatureParts(signature: Signature): SignatureParts;
24792477

24802478
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
24812479
getSymbolAtLocation(node: Node): Symbol;
@@ -3230,6 +3228,12 @@ namespace ts {
32303228
declaration?: SignatureDeclaration;
32313229
}
32323230

3231+
export interface SignatureParts {
3232+
typeParameters: TypeParameterDeclaration[] | undefined;
3233+
parameters: ParameterDeclaration[];
3234+
type: TypeNode;
3235+
}
3236+
32333237
/* @internal */
32343238
export interface TypeMapper {
32353239
(t: TypeParameter): Type;

src/services/codefixes/helpers.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ namespace ts.codefix {
9393
// TODO: get parameters working.
9494
// TODO: add support for type parameters.
9595
const signature = signatures[0];
96-
const signatureParts = getSignatureParts(signature);
96+
const signatureParts = checker.createSignatureParts(signature);
9797
return createStubbedMethod(modifiers, name, optional, signatureParts.typeParameters, signatureParts.parameters, signatureParts.type);
9898
}
9999

100100
let signatureDeclarations = [];
101101
for (let i = 0; i < signatures.length; i++) {
102102
// TODO: make signatures instead of methods
103103
const signature = signatures[i];
104-
const signatureParts = getSignatureParts(signature);
104+
const signatureParts = checker.createSignatureParts(signature);
105105
signatureDeclarations.push(createMethod(
106106
/*decorators*/ undefined
107107
, modifiers
@@ -116,7 +116,7 @@ namespace ts.codefix {
116116

117117
if (declarations.length > signatures.length) {
118118
let signature = checker.getSignatureFromDeclaration(declarations[declarations.length - 1] as SignatureDeclaration);
119-
const signatureParts = getSignatureParts(signature);
119+
const signatureParts = checker.createSignatureParts(signature);
120120
signatureDeclarations.push(createStubbedMethod(modifiers, name, optional, signatureParts.typeParameters, signatureParts.parameters, signatureParts.type));
121121
}
122122
else {
@@ -128,20 +128,6 @@ namespace ts.codefix {
128128
default:
129129
return undefined;
130130
}
131-
132-
type SignatureParts = {
133-
typeParameters: TypeParameterDeclaration[];
134-
parameters: ParameterDeclaration[];
135-
type: TypeNode;
136-
}
137-
138-
function getSignatureParts(signature: Signature): SignatureParts {
139-
return {
140-
typeParameters: signature.typeParameters && signature.typeParameters.map(checker.createTypeParameterDeclarationFromType),
141-
parameters: signature.getParameters().map(symbol => checker.createParameterDeclarationFromSymbol(symbol)),
142-
type: createTypeNodeExceptAny(checker.getReturnTypeOfSignature(signature), checker)
143-
}
144-
}
145131
}
146132

147133
function createMethodImplementingSignatures(signatures: Signature[], name: PropertyName, optional: boolean, modifiers: Modifier[] | undefined): MethodDeclaration {
@@ -234,9 +220,4 @@ namespace ts.codefix {
234220
}
235221
return undefined;
236222
}
237-
238-
function createTypeNodeExceptAny(type: Type, checker: TypeChecker) {
239-
const typeNode = checker.createTypeNode(type);
240-
return typeNode && typeNode.kind !== SyntaxKind.AnyKeyword ? typeNode : undefined;
241-
}
242223
}

0 commit comments

Comments
 (0)