mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-25 16:07:52 -05:00
Add tests and fix rest parameters
This commit is contained in:
@@ -114,18 +114,29 @@ namespace ts.codefix {
|
||||
|
||||
newSignatureDeclaration.parameters = createNodeArray<ParameterDeclaration>();
|
||||
for (let i = 0; i < maxArgs - 1; i++) {
|
||||
const newParameter = createParameterDeclaration(i, minArgumentCount, newSignatureDeclaration);
|
||||
const newParameter = createParameterDeclaration(i, minArgumentCount, anyTypeNode, newSignatureDeclaration);
|
||||
newSignatureDeclaration.parameters.push(newParameter);
|
||||
}
|
||||
|
||||
const lastParameter = createParameterDeclaration(maxArgs - 1, minArgumentCount, newSignatureDeclaration);
|
||||
let lastParameter: ParameterDeclaration;
|
||||
if (hasRestParameter) {
|
||||
lastParameter.dotDotDotToken = createToken(SyntaxKind.DotDotDotToken);
|
||||
|
||||
const anyArrayTypeNode = createNode(SyntaxKind.ArrayType) as ArrayTypeNode;
|
||||
anyArrayTypeNode.elementType = anyTypeNode;
|
||||
|
||||
if (!allMaxArgsAreRest) {
|
||||
const newParameter = createParameterDeclaration(maxArgs - 1, minArgumentCount, newSignatureDeclaration);
|
||||
const newParameter = createParameterDeclaration(maxArgs - 1, minArgumentCount, anyTypeNode, newSignatureDeclaration);
|
||||
newSignatureDeclaration.parameters.push(newParameter);
|
||||
lastParameter = createParameterDeclaration(maxArgs, minArgumentCount, anyArrayTypeNode, newSignatureDeclaration);
|
||||
}
|
||||
else {
|
||||
lastParameter = createParameterDeclaration(maxArgs - 1, minArgumentCount, anyArrayTypeNode, newSignatureDeclaration);
|
||||
}
|
||||
|
||||
lastParameter.dotDotDotToken = createToken(SyntaxKind.DotDotDotToken);
|
||||
}
|
||||
else {
|
||||
lastParameter = createParameterDeclaration(maxArgs - 1, minArgumentCount, anyTypeNode, newSignatureDeclaration);
|
||||
}
|
||||
|
||||
newSignatureDeclaration.parameters.push(lastParameter);
|
||||
@@ -135,12 +146,12 @@ namespace ts.codefix {
|
||||
|
||||
return checker.getSignatureFromDeclaration(newSignatureDeclaration);
|
||||
|
||||
function createParameterDeclaration(index: number, minArgCount: number, enclosingSignatureDeclaration: SignatureDeclaration): ParameterDeclaration {
|
||||
function createParameterDeclaration(index: number, minArgCount: number, typeNode: TypeNode, enclosingSignatureDeclaration: SignatureDeclaration): ParameterDeclaration {
|
||||
const newParameter = createNode(SyntaxKind.Parameter) as ParameterDeclaration;
|
||||
newParameter.symbol = checker.createSymbol(SymbolFlags.FunctionScopedVariable, "arg" + index);
|
||||
newParameter.symbol.valueDeclaration = newParameter;
|
||||
newParameter.symbol.declarations = [newParameter];
|
||||
newParameter.type = anyTypeNode;
|
||||
newParameter.type = typeNode;
|
||||
newParameter.parent = enclosingSignatureDeclaration;
|
||||
if (index >= minArgCount) {
|
||||
newParameter.questionToken = optionalToken;
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// f1();
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`f1(){
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -1,14 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// f(x: number, y: string)
|
||||
//// f(x: number, y: string): I
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
f(x: number,y: string){
|
||||
f(x: number,y: string): I {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// f1(): string;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`f1(): string {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// method(a: number, ...b: string[]): boolean;
|
||||
//// method(a: string, ...b: number[]): Function;
|
||||
//// method(a: string): Function;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
method(a: number, ...b: string[]): boolean;
|
||||
method(a: string, ...b: number[]): Function;
|
||||
method(a: string): Function;
|
||||
method(arg0: any, ...arg1?: any[]) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// method(a: number, ...b: string[]): boolean;
|
||||
//// method(a: string, b: number): Function;
|
||||
//// method(a: string): Function;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
method(a: number, ...b: string[]): boolean;
|
||||
method(a: string, b: number): Function;
|
||||
method(a: string): Function;
|
||||
method(arg0: any, arg1?: any, ...arg2?: any[]) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
Reference in New Issue
Block a user