-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codefix for implementing interfaces #11547
Changes from 51 commits
1438f9a
7a5cb5f
bf3e487
6b4f6b5
151f940
d1cea73
c2feab6
f74872d
2abf906
132b746
ecc029f
a66b0ae
5d9a4e3
3ac9ffa
d24236b
7758e6d
7272833
834245c
c89b97b
16dc834
cbaea99
bc21346
99ae5d9
aa6ecd4
3240000
0380f3f
1b60a97
e5279fd
04968ab
d02eb6c
3b0b696
36c5bef
1b8486d
b7b30aa
71d1744
8c35185
bc1bb0e
0ce53f0
b26ba83
11cea6a
7141a2a
55bf3e3
4441380
1ec234a
6bd35fb
4973852
1d6ef6a
d842a6f
b1e97b3
c650c33
0591e1b
263734f
4b202ab
357ed7e
f6fc320
efd16c7
bba96da
cfe50d1
ad3035d
d8b359f
6400d53
c010a0e
395d736
d7d4bf6
a94d955
43afb80
6ed8d18
389959a
69118cd
4af0e2a
680af0f
16b146f
f37640a
5d6a714
bf48564
ba80ce6
8134d64
0c1772b
f0c7713
c511aea
5cd0ea3
c22e47d
c1a41b9
2f51b36
97b3d7a
819a654
5e48e33
1338b94
b9ae36c
d724517
469745b
1ba6c86
ad01110
3cfac08
4673812
4b02099
8be8819
d75d548
4af3937
97f18c9
3fc94bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,20 +74,27 @@ namespace ts { | |
getGlobalDiagnostics, | ||
getTypeOfSymbolAtLocation, | ||
getSymbolsOfParameterPropertyDeclaration, | ||
getTypeOfSymbol, | ||
getDeclaredTypeOfSymbol, | ||
getPropertiesOfType, | ||
getPropertyOfType, | ||
getSignaturesOfType, | ||
getIndexTypeOfType, | ||
getBaseTypes, | ||
getUnionType, | ||
getIntersectionType, | ||
getTypeFromTypeReference, | ||
getReturnTypeOfSignature, | ||
resolveStructuredTypeMembers, | ||
getNonNullableType, | ||
getSymbolsInScope, | ||
getSymbolOfNode, | ||
getSymbolAtLocation, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would say use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. |
||
getShorthandAssignmentValueSymbol, | ||
getExportSpecifierLocalTargetSymbol, | ||
getTypeAtLocation: getTypeOfNode, | ||
getPropertySymbolOfDestructuringAssignment, | ||
signatureToString, | ||
typeToString, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider inlining these two using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
getSymbolDisplayBuilder, | ||
symbolToString, | ||
|
@@ -1312,7 +1319,9 @@ namespace ts { | |
return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol); | ||
} | ||
|
||
// Resolves a qualified name and any involved aliases | ||
/** | ||
* Resolves a qualified name and any involved aliases. | ||
*/ | ||
function resolveEntityName(name: EntityNameOrEntityNameExpression, meaning: SymbolFlags, ignoreErrors?: boolean, dontResolveAlias?: boolean, location?: Node): Symbol | undefined { | ||
if (nodeIsMissing(name)) { | ||
return undefined; | ||
|
@@ -2033,7 +2042,7 @@ namespace ts { | |
return result || types; | ||
} | ||
|
||
function visibilityToString(flags: ModifierFlags) { | ||
function visibilityToString(flags: ModifierFlags): string | undefined { | ||
if (flags === ModifierFlags.Private) { | ||
return "private"; | ||
} | ||
|
@@ -2672,6 +2681,11 @@ namespace ts { | |
} | ||
|
||
function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { | ||
const returnType = getReturnTypeOfSignature(signature); | ||
if (flags & TypeFormatFlags.supressAnyReturnType && isTypeAny(returnType)) { | ||
return; | ||
} | ||
|
||
if (flags & TypeFormatFlags.WriteArrowStyleSignature) { | ||
writeSpace(writer); | ||
writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken); | ||
|
@@ -2685,7 +2699,6 @@ namespace ts { | |
buildTypePredicateDisplay(signature.typePredicate, writer, enclosingDeclaration, flags, symbolStack); | ||
} | ||
else { | ||
const returnType = getReturnTypeOfSignature(signature); | ||
buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack); | ||
} | ||
} | ||
|
@@ -3657,11 +3670,13 @@ namespace ts { | |
return signatures; | ||
} | ||
|
||
// The base constructor of a class can resolve to | ||
// undefinedType if the class has no extends clause, | ||
// unknownType if an error occurred during resolution of the extends expression, | ||
// nullType if the extends expression is the null value, or | ||
// an object type with at least one construct signature. | ||
/** | ||
* The base constructor of a class can resolve to | ||
* * undefinedType if the class has no extends clause, | ||
* * unknownType if an error occurred during resolution of the extends expression, | ||
* * nullType if the extends expression is the null value, or | ||
* * an object type with at least one construct signature. | ||
*/ | ||
function getBaseConstructorTypeOfClass(type: InterfaceType): Type { | ||
if (!type.resolvedBaseConstructorType) { | ||
const baseTypeNode = getBaseTypeNodeOfClass(type); | ||
|
@@ -4132,7 +4147,7 @@ namespace ts { | |
return <InterfaceTypeWithDeclaredMembers>type; | ||
} | ||
|
||
function getTypeWithThisArgument(type: Type, thisArgument?: Type) { | ||
function getTypeWithThisArgument(type: Type, thisArgument?: Type): Type { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why adding the type annotation? Can't they be inferred? |
||
if (getObjectFlags(type) & ObjectFlags.Reference) { | ||
return createTypeReference((<TypeReference>type).target, | ||
concatenate((<TypeReference>type).typeArguments, [thisArgument || (<TypeReference>type).target.thisType])); | ||
|
@@ -4353,6 +4368,9 @@ namespace ts { | |
setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); | ||
} | ||
|
||
/** | ||
* Converts an AnonymousType to a ResolvedType. | ||
*/ | ||
function resolveAnonymousTypeMembers(type: AnonymousType) { | ||
const symbol = type.symbol; | ||
if (type.target) { | ||
|
@@ -6750,10 +6768,12 @@ namespace ts { | |
} | ||
} | ||
|
||
// Compare two types and return | ||
// Ternary.True if they are related with no assumptions, | ||
// Ternary.Maybe if they are related with assumptions of other relationships, or | ||
// Ternary.False if they are not related. | ||
/** | ||
* Compare two types and return | ||
* * Ternary.True if they are related with no assumptions, | ||
* * Ternary.Maybe if they are related with assumptions of other relationships, or | ||
* * Ternary.False if they are not related. | ||
*/ | ||
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary { | ||
let result: Ternary; | ||
if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2258,22 +2258,29 @@ namespace ts { | |
|
||
export interface TypeChecker { | ||
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type; | ||
getTypeOfSymbol(symbol: Symbol): Type; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is getTypeOfSymbolAtLocation not sufficient here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is. Changed. |
||
getDeclaredTypeOfSymbol(symbol: Symbol): Type; | ||
getPropertiesOfType(type: Type): Symbol[]; | ||
getPropertyOfType(type: Type, propertyName: string): Symbol; | ||
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; | ||
getIndexTypeOfType(type: Type, kind: IndexKind): Type; | ||
getBaseTypes(type: InterfaceType): ObjectType[]; | ||
resolveStructuredTypeMembers(type: StructuredType): ResolvedType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should not be exposed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unexposed. |
||
getReturnTypeOfSignature(signature: Signature): Type; | ||
getNonNullableType(type: Type): Type; | ||
getIntersectionType(types: Type[], aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type; | ||
getUnionType(types: Type[], subtypeReduction?: boolean, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type; | ||
|
||
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]; | ||
getSymbolOfNode(node: Node): Symbol; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getSymbolAtLocation ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. |
||
getSymbolAtLocation(node: Node): Symbol; | ||
getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): Symbol[]; | ||
getShorthandAssignmentValueSymbol(location: Node): Symbol; | ||
getExportSpecifierLocalTargetSymbol(location: ExportSpecifier): Symbol; | ||
getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol; | ||
getTypeAtLocation(node: Node): Type; | ||
getTypeFromTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference): Type; | ||
signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string; | ||
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; | ||
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string; | ||
getSymbolDisplayBuilder(): SymbolDisplayBuilder; | ||
|
@@ -2357,6 +2364,7 @@ namespace ts { | |
InFirstTypeArgument = 0x00000100, // Writing first type argument of the instantiated type | ||
InTypeAlias = 0x00000200, // Writing type in type alias declaration | ||
UseTypeAliasValue = 0x00000400, // Serialize the type instead of using type-alias. This is needed when we emit declaration file. | ||
supressAnyReturnType = 0x00000800, // If the return type is any-like, don't offer a return type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capital first letter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. |
||
} | ||
|
||
export const enum SymbolFormatFlags { | ||
|
@@ -2776,7 +2784,7 @@ namespace ts { | |
objectFlags: ObjectFlags; | ||
} | ||
|
||
// Class and interface types (TypeFlags.Class and TypeFlags.Interface) | ||
/** Class and interface types (TypeFlags.Class and TypeFlags.Interface). */ | ||
export interface InterfaceType extends ObjectType { | ||
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic) | ||
outerTypeParameters: TypeParameter[]; // Outer type parameters (undefined if none) | ||
|
@@ -2796,14 +2804,16 @@ namespace ts { | |
declaredNumberIndexInfo: IndexInfo; // Declared numeric indexing info | ||
} | ||
|
||
// Type references (TypeFlags.Reference). When a class or interface has type parameters or | ||
// a "this" type, references to the class or interface are made using type references. The | ||
// typeArguments property specifies the types to substitute for the type parameters of the | ||
// class or interface and optionally includes an extra element that specifies the type to | ||
// substitute for "this" in the resulting instantiation. When no extra argument is present, | ||
// the type reference itself is substituted for "this". The typeArguments property is undefined | ||
// if the class or interface has no type parameters and the reference isn't specifying an | ||
// explicit "this" argument. | ||
/** | ||
* Type references (TypeFlags.Reference). When a class or interface has type parameters or | ||
* a "this" type, references to the class or interface are made using type references. The | ||
* typeArguments property specifies the types to substitute for the type parameters of the | ||
* class or interface and optionally includes an extra element that specifies the type to | ||
* substitute for "this" in the resulting instantiation. When no extra argument is present, | ||
* the type reference itself is substituted for "this". The typeArguments property is undefined | ||
* if the class or interface has no type parameters and the reference isn't specifying an | ||
* explicit "this" argument. | ||
*/ | ||
export interface TypeReference extends ObjectType { | ||
target: GenericType; // Type reference target | ||
typeArguments: Type[]; // Type reference type arguments (undefined if none) | ||
|
@@ -2841,7 +2851,6 @@ namespace ts { | |
finalArrayType?: Type; // Final array type of evolving array type | ||
} | ||
|
||
/* @internal */ | ||
// Resolved object, union, or intersection type | ||
export interface ResolvedType extends ObjectType, UnionOrIntersectionType { | ||
members: SymbolTable; // Properties by name | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is not used i would remove it for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.