diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 294c4991286..4ccc8f84de9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -107,9 +107,8 @@ namespace ts { getReturnTypeOfSignature, getNonNullableType, createTypeNode, - createTypeParameterDeclarationFromType, createIndexSignatureFromIndexInfo, - createParameterDeclarationFromSymbol, + createSignatureParts, getSymbolsInScope: (location, meaning) => { location = getParseTreeNode(location); return location ? getSymbolsInScope(location, meaning) : []; @@ -2222,13 +2221,6 @@ namespace ts { return parameterNode; } - /* @internal */ - type SignatureParts = { - typeParameters: TypeParameterDeclaration[] | undefined; - parameters: ParameterDeclaration[]; - type: TypeNode; - } - // TODO: expose this, remove copy from helper, possibly don't expose createParameter/TypeParameter? function createSignatureParts(signature: Signature): SignatureParts { return { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index acca1b7398c..679e11fa255 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2468,14 +2468,12 @@ namespace ts { /* @internal */ getParameterType(signature: Signature, parameterIndex: number): Type; getNonNullableType(type: Type): Type; - /** Note that the resulting type node cannot be checked. */ + /** Note that the resulting nodes cannot be checked. */ createTypeNode(type: Type): TypeNode; - /** Note that the resulting type node cannot be checked. */ - createTypeParameterDeclarationFromType(type: Type): TypeParameterDeclaration; - /** Note that the resulting type node cannot be checked. */ - createIndexSignatureFromIndexInfo(indexInfo: IndexInfo, kind: IndexKind): IndexSignatureDeclaration - /** Note that the resulting type node cannot be checked. */ - createParameterDeclarationFromSymbol(parameterSymbol: Symbol): ParameterDeclaration; + /** Note that the resulting nodes cannot be checked. */ + createIndexSignatureFromIndexInfo(indexInfo: IndexInfo, kind: IndexKind): IndexSignatureDeclaration; + /** Note that the resulting nodes cannot be checked. */ + createSignatureParts(signature: Signature): SignatureParts; getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]; getSymbolAtLocation(node: Node): Symbol; @@ -3230,6 +3228,12 @@ namespace ts { declaration?: SignatureDeclaration; } + export interface SignatureParts { + typeParameters: TypeParameterDeclaration[] | undefined; + parameters: ParameterDeclaration[]; + type: TypeNode; + } + /* @internal */ export interface TypeMapper { (t: TypeParameter): Type; diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index e98235c3c8b..a8347cb0a9b 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -93,7 +93,7 @@ namespace ts.codefix { // TODO: get parameters working. // TODO: add support for type parameters. const signature = signatures[0]; - const signatureParts = getSignatureParts(signature); + const signatureParts = checker.createSignatureParts(signature); return createStubbedMethod(modifiers, name, optional, signatureParts.typeParameters, signatureParts.parameters, signatureParts.type); } @@ -101,7 +101,7 @@ namespace ts.codefix { for (let i = 0; i < signatures.length; i++) { // TODO: make signatures instead of methods const signature = signatures[i]; - const signatureParts = getSignatureParts(signature); + const signatureParts = checker.createSignatureParts(signature); signatureDeclarations.push(createMethod( /*decorators*/ undefined , modifiers @@ -116,7 +116,7 @@ namespace ts.codefix { if (declarations.length > signatures.length) { let signature = checker.getSignatureFromDeclaration(declarations[declarations.length - 1] as SignatureDeclaration); - const signatureParts = getSignatureParts(signature); + const signatureParts = checker.createSignatureParts(signature); signatureDeclarations.push(createStubbedMethod(modifiers, name, optional, signatureParts.typeParameters, signatureParts.parameters, signatureParts.type)); } else { @@ -128,20 +128,6 @@ namespace ts.codefix { default: return undefined; } - - type SignatureParts = { - typeParameters: TypeParameterDeclaration[]; - parameters: ParameterDeclaration[]; - type: TypeNode; - } - - function getSignatureParts(signature: Signature): SignatureParts { - return { - typeParameters: signature.typeParameters && signature.typeParameters.map(checker.createTypeParameterDeclarationFromType), - parameters: signature.getParameters().map(symbol => checker.createParameterDeclarationFromSymbol(symbol)), - type: createTypeNodeExceptAny(checker.getReturnTypeOfSignature(signature), checker) - } - } } function createMethodImplementingSignatures(signatures: Signature[], name: PropertyName, optional: boolean, modifiers: Modifier[] | undefined): MethodDeclaration { @@ -234,9 +220,4 @@ namespace ts.codefix { } return undefined; } - - function createTypeNodeExceptAny(type: Type, checker: TypeChecker) { - const typeNode = checker.createTypeNode(type); - return typeNode && typeNode.kind !== SyntaxKind.AnyKeyword ? typeNode : undefined; - } } \ No newline at end of file