fix(44059): omit duplicate types (#45739)
This commit is contained in:
parent
2d4b243195
commit
0a628ff0c9
|
@ -1000,13 +1000,25 @@ namespace ts.codefix {
|
|||
if (usage.numberIndex) {
|
||||
types.push(checker.createArrayType(combineFromUsage(usage.numberIndex)));
|
||||
}
|
||||
if (usage.properties?.size || usage.calls?.length || usage.constructs?.length || usage.stringIndex) {
|
||||
if (usage.properties?.size || usage.constructs?.length || usage.stringIndex) {
|
||||
types.push(inferStructuralType(usage));
|
||||
}
|
||||
|
||||
types.push(...(usage.candidateTypes || []).map(t => checker.getBaseTypeOfLiteralType(t)));
|
||||
types.push(...inferNamedTypesFromProperties(usage));
|
||||
const candidateTypes = (usage.candidateTypes || []).map(t => checker.getBaseTypeOfLiteralType(t));
|
||||
const callsType = usage.calls?.length ? inferStructuralType(usage) : undefined;
|
||||
if (callsType && candidateTypes) {
|
||||
types.push(checker.getUnionType([callsType, ...candidateTypes], UnionReduction.Subtype));
|
||||
}
|
||||
else {
|
||||
if (callsType) {
|
||||
types.push(callsType);
|
||||
}
|
||||
if (length(candidateTypes)) {
|
||||
types.push(...candidateTypes);
|
||||
}
|
||||
}
|
||||
|
||||
types.push(...inferNamedTypesFromProperties(usage));
|
||||
return types;
|
||||
}
|
||||
|
||||
|
|
13
tests/cases/fourslash/codeFixInferFromUsageVariable4.ts
Normal file
13
tests/cases/fourslash/codeFixInferFromUsageVariable4.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noImplicitAny: false
|
||||
////[|let foo;|]
|
||||
////
|
||||
////foo?.();
|
||||
////foo = () => {}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Infer type of 'foo' from usage",
|
||||
index: 0,
|
||||
newRangeContent: "let foo: () => void;"
|
||||
});
|
Loading…
Reference in a new issue