diff --git a/src/services/codefixes/changeExtendsToImplementsFix.ts b/src/services/codefixes/changeExtendsToImplementsFix.ts new file mode 100644 index 00000000000..fd91ba1c8be --- /dev/null +++ b/src/services/codefixes/changeExtendsToImplementsFix.ts @@ -0,0 +1,33 @@ +/* @internal */ +namespace ts.codefix { + registerCodeFix({ + errorCodes: [Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements.code], + getCodeActions: (context: CodeFixContext) => { + const sourceFile = context.sourceFile; + const start = context.span.start; + const token = getTokenAtPosition(sourceFile, start); + const textChanges: TextChange[] = []; + + if (token.kind === SyntaxKind.Identifier && token.parent.parent.kind === SyntaxKind.HeritageClause) { + const children = (token.parent.parent).getChildren(); + ts.forEach(children, child => { + if (child.kind === SyntaxKind.ExtendsKeyword) { + textChanges.push({ newText: " implements", span: { start: child.pos, length: child.end - child.pos } }); + } + }); + } + + if (textChanges.length > 0) { + return [{ + description: getLocaleSpecificMessage(Diagnostics.Change_extends_to_implements), + changes: [{ + fileName: sourceFile.fileName, + textChanges: textChanges + }] + }]; + } + + return undefined; + } + }); +} diff --git a/src/services/codefixes/fixes.ts b/src/services/codefixes/fixes.ts index d64a99ca1b9..b1fdb9d43da 100644 --- a/src/services/codefixes/fixes.ts +++ b/src/services/codefixes/fixes.ts @@ -1 +1,3 @@ -/// +/// +/// +/// diff --git a/src/services/codefixes/interfaceFixes.ts b/src/services/codefixes/interfaceFixes.ts new file mode 100644 index 00000000000..49d69497333 --- /dev/null +++ b/src/services/codefixes/interfaceFixes.ts @@ -0,0 +1,268 @@ +/* @internal */ +namespace ts.codefix { + registerCodeFix({ + errorCodes: [Diagnostics.Type_0_is_not_assignable_to_type_1.code], + getCodeActions: (context: CodeFixContext) => { + const sourceFile = context.sourceFile; + const start = context.span.start; + const token = getTokenAtPosition(sourceFile, start); + const checker = context.program.getTypeChecker(); + let textChanges: TextChange[] = []; + + if (token.kind === SyntaxKind.Identifier && token.parent.kind === SyntaxKind.VariableDeclaration) { + const variableDeclaration = token.parent; + const membersAndStartPosObject = getMembersAndStartPosFromReference(variableDeclaration); + const variableMembers = membersAndStartPosObject.members; + const trackingAddedMembers: string[] = []; + const startPos: number = membersAndStartPosObject.startPos; + + if (variableDeclaration.type.kind === SyntaxKind.TypeReference) { + textChanges = textChanges.concat(getChanges(variableDeclaration.type, variableMembers, startPos, checker, /*reference*/ true, trackingAddedMembers, context.newLineCharacter)); + } + else if (variableDeclaration.type.kind === SyntaxKind.UnionType) { + const types = (variableDeclaration.type).types; + ts.forEach(types, t => { + textChanges = textChanges.concat(getChanges(t, variableMembers, startPos, checker, /*reference*/ true, trackingAddedMembers, context.newLineCharacter)); + }); + } + } + + if (textChanges.length > 0) { + return [{ + description: getLocaleSpecificMessage(Diagnostics.Implement_interface_on_reference), + changes: [{ + fileName: sourceFile.fileName, + textChanges: textChanges + }] + }]; + } + + return undefined; + } + }); + + registerCodeFix({ + errorCodes: [Diagnostics.Class_0_incorrectly_implements_interface_1.code], + getCodeActions: (context: CodeFixContext) => { + const sourceFile = context.sourceFile; + const start = context.span.start; + const token = getTokenAtPosition(sourceFile, start); + const checker = context.program.getTypeChecker(); + + let textChanges: TextChange[] = []; + + if (token.kind === SyntaxKind.Identifier && token.parent.kind === SyntaxKind.ClassDeclaration) { + const classDeclaration = token.parent; + const startPos: number = classDeclaration.members.pos; + const classMembers = getClassMembers(classDeclaration); + const trackingAddedMembers: string[] = []; + const interfaceClauses = ts.getClassImplementsHeritageClauseElements(classDeclaration); + + for (let i = 0; interfaceClauses && i < interfaceClauses.length; i++) { + textChanges = textChanges.concat(getChanges(interfaceClauses[i], classMembers, startPos, checker, /*reference*/ false, trackingAddedMembers, context.newLineCharacter)); + } + } + + if (textChanges.length > 0) { + return [{ + description: getLocaleSpecificMessage(Diagnostics.Implement_interface_on_class), + changes: [{ + fileName: sourceFile.fileName, + textChanges: textChanges + }] + }]; + } + + return undefined; + } + }); + + registerCodeFix({ + errorCodes: [Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2.code], + getCodeActions: (context: CodeFixContext) => { + const sourceFile = context.sourceFile; + const start = context.span.start; + const token = getTokenAtPosition(sourceFile, start); + const checker = context.program.getTypeChecker(); + + let textChanges: TextChange[] = []; + + if (token.kind === SyntaxKind.Identifier && token.parent.kind === SyntaxKind.ClassDeclaration) { + const classDeclaration = token.parent; + const startPos = classDeclaration.members.pos; + const classMembers = getClassMembers(classDeclaration); + const trackingAddedMembers: string[] = []; + const extendsClause = ts.getClassExtendsHeritageClauseElement(classDeclaration); + textChanges = textChanges.concat(getChanges(extendsClause, classMembers, startPos, checker, /*reference*/ false, trackingAddedMembers, context.newLineCharacter)); + } + + if (textChanges.length > 0) { + return [{ + description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class), + changes: [{ + fileName: sourceFile.fileName, + textChanges: textChanges + }] + }]; + } + + return undefined; + } + }); + + function getChanges(interfaceClause: Node, existingMembers: string[], startPos: number, checker: TypeChecker, reference: boolean, trackingAddedMembers: string[], newLineCharacter: string): TextChange[] { + const type = checker.getTypeAtLocation(interfaceClause); + const changesArray: TextChange[] = []; + + if (type && type.symbol && type.symbol.declarations) { + const interfaceMembers = getMembers(type.symbol.declarations[0], checker); + for (let j = 0; interfaceMembers && j < interfaceMembers.length; j++) { + if (interfaceMembers[j].name && existingMembers.indexOf(interfaceMembers[j].name.getText()) === -1) { + if (interfaceMembers[j].kind === SyntaxKind.PropertySignature) { + const interfaceProperty = interfaceMembers[j]; + if (trackingAddedMembers.indexOf(interfaceProperty.name.getText()) === -1) { + let propertyText = ""; + if (reference) { + propertyText = `${interfaceProperty.name.getText()} : ${getDefaultValue(interfaceProperty.type.kind)},${newLineCharacter}`; + } + else { + propertyText = interfaceProperty.getText(); + const stringToAdd = !(propertyText.match(/;$/)) ? `;${newLineCharacter}` : newLineCharacter; + propertyText += stringToAdd; + } + changesArray.push({ newText: propertyText, span: { start: startPos, length: 0 } }); + trackingAddedMembers.push(interfaceProperty.name.getText()); + } + } + else if (interfaceMembers[j].kind === SyntaxKind.MethodSignature || interfaceMembers[j].kind === SyntaxKind.MethodDeclaration) { + const interfaceMethod = interfaceMembers[j]; + handleMethods(interfaceMethod, startPos, reference, trackingAddedMembers, changesArray, newLineCharacter); + } + } + } + } + + if (reference && existingMembers.length === 0 && changesArray.length > 0) { + let lastValue = changesArray[changesArray.length - 1].newText; + lastValue = `${lastValue.substr(0, lastValue.length - (newLineCharacter.length + 1))} ${newLineCharacter}`; + changesArray[changesArray.length - 1].newText = lastValue; + } + + return changesArray; + } + + function getMembers(declaration: InterfaceDeclaration, checker: TypeChecker): TypeElement[] { + const clauses = getInterfaceBaseTypeNodes(declaration); + let result: TypeElement[] = []; + for (let i = 0; clauses && i < clauses.length; i++) { + const type = checker.getTypeAtLocation(clauses[i]); + if (type && type.symbol && type.symbol.declarations) { + result = result.concat(getMembers(type.symbol.declarations[0], checker)); + } + } + + if (declaration.members) { + result = result.concat(declaration.members); + } + + return result; + } + + function getClassMembers(classDeclaration: ClassDeclaration): string[] { + const classMembers: string[] = []; + for (let i = 0; classDeclaration.members && i < classDeclaration.members.length; i++) { + if (classDeclaration.members[i].name) { + classMembers.push(classDeclaration.members[i].name.getText()); + } + } + return classMembers; + } + + function getMembersAndStartPosFromReference(variableDeclaration: VariableDeclaration): { startPos: number, members: string[] } { + const children = variableDeclaration.getChildren(); + const variableMembers: string[] = []; + let startPos = 0; + + ts.forEach(children, child => { + if (child.kind === SyntaxKind.ObjectLiteralExpression) { + const properties = (child).properties; + if (properties) { + startPos = properties.pos; + } + for (let j = 0; properties && j < properties.length; j++) { + if (properties[j].name) { + variableMembers.push(properties[j].name.getText()); + } + } + } + }); + + return { startPos: startPos, members: variableMembers }; + } + + function getDefaultValue(kind: SyntaxKind): string { + switch (kind) { + case SyntaxKind.StringKeyword: + return '""'; + case SyntaxKind.BooleanKeyword: + return "false"; + case SyntaxKind.NumberKeyword: + return "0"; + default: + return "null"; + } + } + + function handleMethods(interfaceMethod: MethodSignature, startPos: number, isReference: boolean, trackingAddedMembers: string[], textChanges: TextChange[], newLineCharacter: string) { + const methodBody = "throw new Error('Method not Implemented');"; + + if (trackingAddedMembers.indexOf(interfaceMethod.name.getText())) { + const methodName = interfaceMethod.name.getText(); + const typeParameterArray: string[] = []; + + for (let i = 0; interfaceMethod.typeParameters && i < interfaceMethod.typeParameters.length; i++) { + typeParameterArray.push(interfaceMethod.typeParameters[i].getText()); + } + + const parameterArray: string[] = []; + for (let j = 0; interfaceMethod.parameters && j < interfaceMethod.parameters.length; j++) { + parameterArray.push(interfaceMethod.parameters[j].getText()); + } + + let methodText = methodName; + if (typeParameterArray.length > 0) { + methodText += "<"; + } + + for (let k = 0; k < typeParameterArray.length; k++) { + methodText += typeParameterArray[k]; + if (k !== typeParameterArray.length - 1) { + methodText += ","; + } + } + + if (typeParameterArray.length > 0) { + methodText += ">"; + } + + methodText += "("; + for (let k = 0; k < parameterArray.length; k++) { + methodText += parameterArray[k]; + if (k !== parameterArray.length - 1) { + methodText += ","; + } + } + + methodText += `)`; + if (interfaceMethod.type) { + methodText += ":" + interfaceMethod.type.getText(); + } + + methodText += `{${newLineCharacter}${methodBody}${newLineCharacter}`; + methodText = isReference ? methodText.concat(`},${newLineCharacter}`) : methodText.concat(`}${newLineCharacter}`); + + textChanges.push({ newText: methodText, span: { start: startPos, length: 0 } }); + trackingAddedMembers.push(interfaceMethod.name.getText()); + } + } +} diff --git a/tests/cases/fourslash/changeExtendsToImplementsFS1.ts b/tests/cases/fourslash/changeExtendsToImplementsFS1.ts new file mode 100644 index 00000000000..a5b9a6375b6 --- /dev/null +++ b/tests/cases/fourslash/changeExtendsToImplementsFS1.ts @@ -0,0 +1,6 @@ +/// + +//// interface I1 {} +//// [|class c1 extends I1|]{} + +verify.codeFixAtPosition("class c1 implements I1"); \ No newline at end of file diff --git a/tests/cases/fourslash/changeExtendsToImplementsFS2.ts b/tests/cases/fourslash/changeExtendsToImplementsFS2.ts new file mode 100644 index 00000000000..b63ab3032eb --- /dev/null +++ b/tests/cases/fourslash/changeExtendsToImplementsFS2.ts @@ -0,0 +1,6 @@ +/// + +////interface I1 {} +////[|class c1 extends I1|]{} + +verify.codeFixAtPosition("class c1 implements I1"); \ No newline at end of file diff --git a/tests/cases/fourslash/unImplementedInterface1.ts b/tests/cases/fourslash/unImplementedInterface1.ts new file mode 100644 index 00000000000..b07db08f12a --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface1.ts @@ -0,0 +1,18 @@ +/// + +//// namespace N1 { +//// export interface I1 { +//// f1(); +//// } +//// } +//// interface I1 { +//// f1(); +//// } +//// +//// class C1 implements N1.I1 {[| +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface10.ts b/tests/cases/fourslash/unImplementedInterface10.ts new file mode 100644 index 00000000000..aa61cbc1836 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface10.ts @@ -0,0 +1,18 @@ +/// + +//// interface I1 { +//// f1() +//// } +//// +//// interface I2 extends I1 { +//// +//// } +//// +//// +//// class C1 implements I2 {[| +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface11.ts b/tests/cases/fourslash/unImplementedInterface11.ts new file mode 100644 index 00000000000..3c819f6b56e --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface11.ts @@ -0,0 +1,19 @@ +/// + +//// interface I1 { +//// +//// } +//// +//// interface I2 extends I1 { +//// f1(); +//// } +//// +//// interface I3 extends I2 {} +//// +//// class C1 implements I3 {[| +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface12.ts b/tests/cases/fourslash/unImplementedInterface12.ts new file mode 100644 index 00000000000..4e9e428fd6d --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface12.ts @@ -0,0 +1,19 @@ +/// + +//// interface I1 { +//// +//// } +//// +//// interface I2 { +//// f1(); +//// } +//// +//// interface I3 extends I2, I1 {} +//// +//// class C1 implements I3 {[| +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface13.ts b/tests/cases/fourslash/unImplementedInterface13.ts new file mode 100644 index 00000000000..fdb0fa1230c --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface13.ts @@ -0,0 +1,19 @@ +/// + +//// interface I1 { +//// f1(); +//// } +//// +//// interface I2 { +//// f1(); +//// } +//// +//// interface I3 extends I2, I1 {} +//// +//// class C1 implements I3 {[| +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface14.ts b/tests/cases/fourslash/unImplementedInterface14.ts new file mode 100644 index 00000000000..ad55fef3cce --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface14.ts @@ -0,0 +1,16 @@ +/// + +//// interface I1 { +//// f1(); +//// f2(); +//// } +//// +//// +//// var x: I1 ={[| +//// |]f2() {} +//// } + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +}, +`); diff --git a/tests/cases/fourslash/unImplementedInterface15.ts b/tests/cases/fourslash/unImplementedInterface15.ts new file mode 100644 index 00000000000..e68f7171ee5 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface15.ts @@ -0,0 +1,15 @@ +/// + +//// interface I1 { +//// f1(); +//// } +//// +//// var x: I1 = {[| +//// +//// |]} + +verify.codeFixAtPosition(` +f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface16.ts b/tests/cases/fourslash/unImplementedInterface16.ts new file mode 100644 index 00000000000..ca992b1eb1e --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface16.ts @@ -0,0 +1,12 @@ +/// + +//// interface I1 { +//// x:string; +//// } +//// +//// +//// var x: I1 ={[| +//// |]} + +verify.codeFixAtPosition(`x : "" +`); diff --git a/tests/cases/fourslash/unImplementedInterface17.ts b/tests/cases/fourslash/unImplementedInterface17.ts new file mode 100644 index 00000000000..e909b60f588 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface17.ts @@ -0,0 +1,11 @@ +/// + +//// interface I1 { +//// x:number; +//// } +//// +//// var x: I1 ={[| +//// |]} + +verify.codeFixAtPosition(`x : 0 +`); diff --git a/tests/cases/fourslash/unImplementedInterface18.ts b/tests/cases/fourslash/unImplementedInterface18.ts new file mode 100644 index 00000000000..9e0f9888bf3 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface18.ts @@ -0,0 +1,12 @@ +/// + +//// interface I1 { +//// x:boolean; +//// } +//// +//// var x: I1 ={[| +//// +//// |]} + +verify.codeFixAtPosition(`x : false +`); diff --git a/tests/cases/fourslash/unImplementedInterface19.ts b/tests/cases/fourslash/unImplementedInterface19.ts new file mode 100644 index 00000000000..de484c282d8 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface19.ts @@ -0,0 +1,13 @@ +/// + +//// interface I1 { +//// x:string; +//// f1(); +//// } +//// +//// var x: I1 ={[| +//// |]f1(){} +//// } + +verify.codeFixAtPosition(`x : "", +`); diff --git a/tests/cases/fourslash/unImplementedInterface2.ts b/tests/cases/fourslash/unImplementedInterface2.ts new file mode 100644 index 00000000000..394c54d4687 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface2.ts @@ -0,0 +1,16 @@ +/// + +//// namespace N1 { +//// export interface I1 { +//// x: number; +//// } +//// } +//// interface I1 { +//// f1(); +//// } +//// +//// class C1 implements N1.I1 {[| +//// |]} + +verify.codeFixAtPosition(`x: number; +`); diff --git a/tests/cases/fourslash/unImplementedInterface20.ts b/tests/cases/fourslash/unImplementedInterface20.ts new file mode 100644 index 00000000000..56a707d21ba --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface20.ts @@ -0,0 +1,14 @@ +/// + +//// interface I1 { +//// x:number; +//// f1(); +//// } +//// +//// +//// var x: I1 ={[| +//// |]f1(){} +//// } + +verify.codeFixAtPosition(`x : 0, +`); diff --git a/tests/cases/fourslash/unImplementedInterface21.ts b/tests/cases/fourslash/unImplementedInterface21.ts new file mode 100644 index 00000000000..867c697e595 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface21.ts @@ -0,0 +1,14 @@ +/// + +//// interface I1 { +//// x:boolean; +//// f1(); +//// } +//// +//// +//// var x: I1 ={[| +//// |]f1(){} +//// } + +verify.codeFixAtPosition(`x : false, +`); diff --git a/tests/cases/fourslash/unImplementedInterface22.ts b/tests/cases/fourslash/unImplementedInterface22.ts new file mode 100644 index 00000000000..8a51577261f --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface22.ts @@ -0,0 +1,12 @@ +/// + +//// interface I1 { +//// x:[string]; +//// } +//// +//// +//// var x: I1 ={[| +//// |]} + +verify.codeFixAtPosition(`x : null +`); diff --git a/tests/cases/fourslash/unImplementedInterface23.ts b/tests/cases/fourslash/unImplementedInterface23.ts new file mode 100644 index 00000000000..8d00689a446 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface23.ts @@ -0,0 +1,14 @@ +/// + +//// interface I1 { +//// x:[string]; +//// f1(); +//// } +//// +//// +//// var x: I1 ={[| +//// |]f1(){} +//// } + +verify.codeFixAtPosition(`x : null, +`); diff --git a/tests/cases/fourslash/unImplementedInterface24.ts b/tests/cases/fourslash/unImplementedInterface24.ts new file mode 100644 index 00000000000..c206789b7f2 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface24.ts @@ -0,0 +1,12 @@ +/// + +//// interface I1 { +//// x:Array; +//// } +//// +//// +//// var x: I1 ={[| +//// |]} + +verify.codeFixAtPosition(`x : null +`); diff --git a/tests/cases/fourslash/unImplementedInterface25.ts b/tests/cases/fourslash/unImplementedInterface25.ts new file mode 100644 index 00000000000..6b2b809efaa --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface25.ts @@ -0,0 +1,14 @@ +/// + +//// interface I1 { +//// x:Array; +//// f1(); +//// } +//// +//// +//// var x: I1 ={[| +//// |]f1(){} +//// } + +verify.codeFixAtPosition(`x : null, +`); diff --git a/tests/cases/fourslash/unImplementedInterface26.ts b/tests/cases/fourslash/unImplementedInterface26.ts new file mode 100644 index 00000000000..a7136f0e70f --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface26.ts @@ -0,0 +1,14 @@ +/// + +//// interface I1 { +//// x:T; +//// } +//// +//// class T {} +//// +//// +//// var x: I1 ={[| +//// |]} + +verify.codeFixAtPosition(`x : null +`); diff --git a/tests/cases/fourslash/unImplementedInterface27.ts b/tests/cases/fourslash/unImplementedInterface27.ts new file mode 100644 index 00000000000..fc12cb57377 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface27.ts @@ -0,0 +1,16 @@ +/// + +//// interface I1 { +//// x:T; +//// f1(); +//// } +//// +//// class T {} +//// +//// +//// var x: I1 ={[| +//// |]f1(){} +//// } + +verify.codeFixAtPosition(`x : null, +`); diff --git a/tests/cases/fourslash/unImplementedInterface28.ts b/tests/cases/fourslash/unImplementedInterface28.ts new file mode 100644 index 00000000000..16cbe47b26c --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface28.ts @@ -0,0 +1,21 @@ +/// + +//// interface I1 { +//// f1(); +//// } +//// +//// interface I2 { +//// f2(); +//// } +//// +//// var x: I1|I2 ={[| +//// +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +f2(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface29.ts b/tests/cases/fourslash/unImplementedInterface29.ts new file mode 100644 index 00000000000..c2719c2e7f9 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface29.ts @@ -0,0 +1,14 @@ +/// + +//// abstract class C1 { +//// f1(){} +//// } +//// +//// class C2 implements C1 {[| +//// |]f2(){} +//// } + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface3.ts b/tests/cases/fourslash/unImplementedInterface3.ts new file mode 100644 index 00000000000..19354ce1c94 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface3.ts @@ -0,0 +1,16 @@ +/// + +//// namespace N1 { +//// export interface I1 { +//// x: number +//// } +//// } +//// interface I1 { +//// f1(); +//// } +//// +//// class C1 implements N1.I1 {[| +//// |]} + +verify.codeFixAtPosition(`x: number; +`); diff --git a/tests/cases/fourslash/unImplementedInterface30.ts b/tests/cases/fourslash/unImplementedInterface30.ts new file mode 100644 index 00000000000..71addef195b --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface30.ts @@ -0,0 +1,18 @@ +/// + +//// abstract class C1 { +//// f1(){} +//// } +//// +//// abstract class C2 extends C1 { +//// +//// } +//// +//// class C3 implements C2 {[| +//// |]f2(){} +//// } + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface31.ts b/tests/cases/fourslash/unImplementedInterface31.ts new file mode 100644 index 00000000000..d56e44911b5 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface31.ts @@ -0,0 +1,18 @@ +/// + +//// abstract class C1 { +//// abstract f1(); +//// } +//// +//// abstract class C2 extends C1 { +//// +//// } +//// +//// class C3 implements C2 {[| +//// |]f2(){} +//// } + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface32.ts b/tests/cases/fourslash/unImplementedInterface32.ts new file mode 100644 index 00000000000..825224f448b --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface32.ts @@ -0,0 +1,18 @@ +/// + +//// abstract class C1 { +//// abstract f1(); +//// } +//// +//// abstract class C2 extends C1 { +//// +//// } +//// +//// class C3 implements C2 {[| +//// |]f2(){} +//// } + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface33.ts b/tests/cases/fourslash/unImplementedInterface33.ts new file mode 100644 index 00000000000..7c3a647ce40 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface33.ts @@ -0,0 +1,18 @@ +/// + +//// abstract class C1 { +//// abstract f1(); +//// } +//// +//// abstract class C2 extends C1 { +//// +//// } +//// +//// class C3 implements C2 {[| +//// |]f2(){} +//// } + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface34.ts b/tests/cases/fourslash/unImplementedInterface34.ts new file mode 100644 index 00000000000..ab7a4f30bea --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface34.ts @@ -0,0 +1,14 @@ +/// + +//// abstract class C1 { +//// abstract f1(); +//// } +//// +//// class C2 extends C1 {[| +//// +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface35.ts b/tests/cases/fourslash/unImplementedInterface35.ts new file mode 100644 index 00000000000..66d47491c41 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface35.ts @@ -0,0 +1,16 @@ +/// + +//// abstract class C1 { +//// abstract f1(); +//// } +//// +//// interface I1 extends C1 {} +//// +//// class C2 implements I1 {[| +//// +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface36.ts b/tests/cases/fourslash/unImplementedInterface36.ts new file mode 100644 index 00000000000..3871414428e --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface36.ts @@ -0,0 +1,20 @@ +/// + +//// abstract class C1 { +//// +//// } +//// +//// abstract class C2 { +//// abstract f1(); +//// } +//// +//// interface I1 extends C1, C2 {} +//// +//// class C3 implements I1 {[| +//// +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface37.ts b/tests/cases/fourslash/unImplementedInterface37.ts new file mode 100644 index 00000000000..2032f2d3461 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface37.ts @@ -0,0 +1,20 @@ +/// + +//// abstract class C1 { +//// abstract f1(); +//// } +//// +//// abstract class C2 extends C1{ +//// +//// } +//// +//// interface I1 extends C2 {} +//// +//// class C3 implements I1 {[| +//// +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface38.ts b/tests/cases/fourslash/unImplementedInterface38.ts new file mode 100644 index 00000000000..c60b9922ef8 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface38.ts @@ -0,0 +1,11 @@ +/// + +//// abstract class C2 { +//// abstract f1(); +//// } +//// +//// var x: C2 = {[| |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +}`); diff --git a/tests/cases/fourslash/unImplementedInterface39.ts b/tests/cases/fourslash/unImplementedInterface39.ts new file mode 100644 index 00000000000..ae85d02b8a3 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface39.ts @@ -0,0 +1,18 @@ +/// + +//// namespace N1 { +//// export interface I1 { +//// f1():string; +//// } +//// } +//// interface I1 { +//// f1(); +//// } +//// +//// class C1 implements N1.I1 {[| +//// |]} + +verify.codeFixAtPosition(`f1():string{ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface4.ts b/tests/cases/fourslash/unImplementedInterface4.ts new file mode 100644 index 00000000000..6e4e64c18d1 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface4.ts @@ -0,0 +1,18 @@ +/// + +//// namespace N1 { +//// export interface I1 { +//// f1() +//// } +//// } +//// interface I1 { +//// f1(); +//// } +//// +//// class C1 implements N1.I1 {[| +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface5.ts b/tests/cases/fourslash/unImplementedInterface5.ts new file mode 100644 index 00000000000..59b3ba85199 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface5.ts @@ -0,0 +1,18 @@ +/// + +//// namespace N1 { +//// export interface I1 { +//// f1(x: number, y: string) +//// } +//// } +//// interface I1 { +//// f1(); +//// } +//// +//// class C1 implements N1.I1 {[| +//// |]} + +verify.codeFixAtPosition(`f1(x: number,y: string){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface6.ts b/tests/cases/fourslash/unImplementedInterface6.ts new file mode 100644 index 00000000000..2310e05fbb0 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface6.ts @@ -0,0 +1,15 @@ +/// + +//// interface I1 { +//// f1(x: number, y: T); +//// } +//// +//// class T {} +//// +//// class C1 implements I1 {[| +//// |]} + +verify.codeFixAtPosition(`f1(x: number,y: T){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface7.ts b/tests/cases/fourslash/unImplementedInterface7.ts new file mode 100644 index 00000000000..125f3e1ffeb --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface7.ts @@ -0,0 +1,15 @@ +/// + +//// interface I1 { +//// f1(x: number, y: C2); +//// } +//// +//// class C2 {} +//// +//// class C1 implements I1 {[| +//// |]} + +verify.codeFixAtPosition(`f1(x: number,y: C2){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface8.ts b/tests/cases/fourslash/unImplementedInterface8.ts new file mode 100644 index 00000000000..2df93c6d7d9 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface8.ts @@ -0,0 +1,15 @@ +/// + +//// interface I1 { +//// f1(x: number, y: C2); +//// } +//// +//// class C2 {} +//// +//// class C1 implements I1 {[| +//// |]} + +verify.codeFixAtPosition(`f1(x: number,y: C2){ + throw new Error('Method not Implemented'); +} +`); diff --git a/tests/cases/fourslash/unImplementedInterface9.ts b/tests/cases/fourslash/unImplementedInterface9.ts new file mode 100644 index 00000000000..5c869996773 --- /dev/null +++ b/tests/cases/fourslash/unImplementedInterface9.ts @@ -0,0 +1,17 @@ +/// + +//// interface I1 { +//// +//// } +//// +//// interface I2 extends I1 { +//// f1(); +//// } +//// +//// class C1 implements I2 {[| +//// |]} + +verify.codeFixAtPosition(`f1(){ + throw new Error('Method not Implemented'); +} +`);