mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Remove SuppressAnyReturnType
Following a discussion with Ryan, it seems best to leave any `any`s in the generated code.
This commit is contained in:
parent
0c467d095f
commit
724f426468
@ -4532,13 +4532,7 @@ namespace ts {
|
||||
const returnType = getReturnTypeOfSignature(signature);
|
||||
returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context);
|
||||
}
|
||||
if (context.flags & NodeBuilderFlags.SuppressAnyReturnType
|
||||
&& kind !== SyntaxKind.FunctionType && kind !== SyntaxKind.ConstructorType) {
|
||||
if (returnTypeNode && returnTypeNode.kind === SyntaxKind.AnyKeyword) {
|
||||
returnTypeNode = undefined;
|
||||
}
|
||||
}
|
||||
else if (!returnTypeNode) {
|
||||
if (!returnTypeNode) {
|
||||
returnTypeNode = createKeywordTypeNode(SyntaxKind.AnyKeyword);
|
||||
}
|
||||
context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum
|
||||
|
||||
@ -3619,6 +3619,7 @@ namespace ts {
|
||||
WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature
|
||||
UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
|
||||
UseOnlyExternalAliasing = 1 << 7, // Only use external aliases for a symbol
|
||||
/** @deprecated Ignored */
|
||||
SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type.
|
||||
WriteTypeParametersInQualifiedName = 1 << 9,
|
||||
MultilineObjectLiterals = 1 << 10, // Always write object literals across multiple lines
|
||||
@ -3660,6 +3661,7 @@ namespace ts {
|
||||
WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature
|
||||
UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
|
||||
// hole because `UseOnlyExternalAliasing` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` instead
|
||||
/** @deprecated Ignored */
|
||||
SuppressAnyReturnType = 1 << 8, // If the return type is any-like, don't offer a return type.
|
||||
// hole because `WriteTypeParametersInQualifiedName` is here in node builder flags, but functions which take old flags use `SymbolFormatFlags` for this instead
|
||||
MultilineObjectLiterals = 1 << 10, // Always print object literals across multiple lines (only used to map into node builder flags)
|
||||
|
||||
@ -155,7 +155,7 @@ namespace ts.codefix {
|
||||
body: Block | undefined,
|
||||
): MethodDeclaration | undefined {
|
||||
const program = context.program;
|
||||
const signatureDeclaration = <MethodDeclaration>program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation | NodeBuilderFlags.SuppressAnyReturnType, getNoopSymbolTrackerWithResolver(context));
|
||||
const signatureDeclaration = <MethodDeclaration>program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation, getNoopSymbolTrackerWithResolver(context));
|
||||
if (!signatureDeclaration) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -2110,6 +2110,7 @@ declare namespace ts {
|
||||
WriteTypeArgumentsOfSignature = 32,
|
||||
UseFullyQualifiedType = 64,
|
||||
UseOnlyExternalAliasing = 128,
|
||||
/** @deprecated Ignored */
|
||||
SuppressAnyReturnType = 256,
|
||||
WriteTypeParametersInQualifiedName = 512,
|
||||
MultilineObjectLiterals = 1024,
|
||||
@ -2138,6 +2139,7 @@ declare namespace ts {
|
||||
UseStructuralFallback = 8,
|
||||
WriteTypeArgumentsOfSignature = 32,
|
||||
UseFullyQualifiedType = 64,
|
||||
/** @deprecated Ignored */
|
||||
SuppressAnyReturnType = 256,
|
||||
MultilineObjectLiterals = 1024,
|
||||
WriteClassExpressionAsTypeLiteral = 2048,
|
||||
|
||||
@ -2110,6 +2110,7 @@ declare namespace ts {
|
||||
WriteTypeArgumentsOfSignature = 32,
|
||||
UseFullyQualifiedType = 64,
|
||||
UseOnlyExternalAliasing = 128,
|
||||
/** @deprecated Ignored */
|
||||
SuppressAnyReturnType = 256,
|
||||
WriteTypeParametersInQualifiedName = 512,
|
||||
MultilineObjectLiterals = 1024,
|
||||
@ -2138,6 +2139,7 @@ declare namespace ts {
|
||||
UseStructuralFallback = 8,
|
||||
WriteTypeArgumentsOfSignature = 32,
|
||||
UseFullyQualifiedType = 64,
|
||||
/** @deprecated Ignored */
|
||||
SuppressAnyReturnType = 256,
|
||||
MultilineObjectLiterals = 1024,
|
||||
WriteClassExpressionAsTypeLiteral = 2048,
|
||||
|
||||
@ -43,7 +43,7 @@ abstract class AbstractCstVisitor {
|
||||
): Set<this_will_be_collapsed>;
|
||||
}
|
||||
class CstVisitorImplementation extends AbstractCstVisitor {
|
||||
Node(arg1: [some.really.long.generated.type.goes.here.you.know.this_.should.be.pretty.simple.Yah[], another.really.long.generated.type.goes.here.too.because.who.cares.about.space.do_.you.feel.me.Yah[]], arg2: [this_will_be_collapsed], arg3: any, arg4: this_is_fine) {
|
||||
Node(arg1: [some.really.long.generated.type.goes.here.you.know.this_.should.be.pretty.simple.Yah[], another.really.long.generated.type.goes.here.too.because.who.cares.about.space.do_.you.feel.me.Yah[]], arg2: [this_will_be_collapsed], arg3: any, arg4: this_is_fine): any {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}`
|
||||
|
||||
@ -43,11 +43,11 @@ class C implements I<number> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
[Symbol.isConcatSpreadable]: boolean;
|
||||
[Symbol.iterator]() {
|
||||
[Symbol.iterator](): any {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
[Symbol.match]: boolean;
|
||||
[Symbol.replace](...args: {}) {
|
||||
[Symbol.replace](...args: {}): any {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
[Symbol.search](str: string): number {
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
//// x: number,
|
||||
//// y: number
|
||||
//// z: number;
|
||||
//// f(),
|
||||
//// f(): number,
|
||||
//// g()
|
||||
//// h();
|
||||
////}
|
||||
@ -18,7 +18,7 @@ verify.codeFix({
|
||||
x: number,
|
||||
y: number
|
||||
z: number;
|
||||
f(),
|
||||
f(): number,
|
||||
g()
|
||||
h();
|
||||
}
|
||||
@ -27,13 +27,13 @@ class C1 implements I1 {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
f() {
|
||||
f(): number {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
g() {
|
||||
g(): any {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
h() {
|
||||
h(): any {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}`,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////interface I {
|
||||
//// f<T extends number>(x: T);
|
||||
//// f<T extends number>(x: T): T;
|
||||
////}
|
||||
////class C implements I {}
|
||||
|
||||
@ -9,10 +9,10 @@ verify.codeFix({
|
||||
description: "Implement interface 'I'",
|
||||
newFileContent:
|
||||
`interface I {
|
||||
f<T extends number>(x: T);
|
||||
f<T extends number>(x: T): T;
|
||||
}
|
||||
class C implements I {
|
||||
f<T extends number>(x: T) {
|
||||
f<T extends number>(x: T): T {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}`,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user