Skip to content

Commit bbbcbd5

Browse files
committed
Merge branch 'master' into type-only-2
2 parents 124d746 + 1dafd09 commit bbbcbd5

11 files changed

+137
-367
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12869,8 +12869,9 @@ namespace ts {
1286912869

1287012870
/** We approximate own properties as non-methods plus methods that are inside the object literal */
1287112871
function isSpreadableProperty(prop: Symbol): boolean {
12872-
return !(prop.flags & (SymbolFlags.Method | SymbolFlags.GetAccessor | SymbolFlags.SetAccessor)) ||
12873-
!prop.declarations.some(decl => isClassLike(decl.parent));
12872+
return !some(prop.declarations, isPrivateIdentifierPropertyDeclaration) &&
12873+
(!(prop.flags & (SymbolFlags.Method | SymbolFlags.GetAccessor | SymbolFlags.SetAccessor)) ||
12874+
!prop.declarations.some(decl => isClassLike(decl.parent)));
1287412875
}
1287512876

1287612877
function getSpreadSymbol(prop: Symbol, readonly: boolean) {
@@ -20385,26 +20386,7 @@ namespace ts {
2038520386
}
2038620387
}
2038720388
else if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) {
20388-
const diag = error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
20389-
20390-
// See GH:32846 - if the user is using a variable whose type is () => T1 | ... | undefined
20391-
// they may have meant to specify the type as (() => T1 | ...) | undefined
20392-
// This is assumed if: the type is a FunctionType, the return type is a Union, the last constituent of
20393-
// the union is `undefined`
20394-
if (type.symbol && type.symbol.declarations.length === 1 && isFunctionTypeNode(type.symbol.declarations[0])) {
20395-
const funcTypeNode = <FunctionTypeNode>type.symbol.declarations[0];
20396-
const returnType = getReturnTypeFromAnnotation(funcTypeNode);
20397-
if (returnType && returnType.flags & TypeFlags.Union) {
20398-
const unionTypes = (<UnionTypeNode>funcTypeNode.type).types;
20399-
if (unionTypes && unionTypes[unionTypes.length - 1].kind === SyntaxKind.UndefinedKeyword) {
20400-
const parenedFuncType = getMutableClone(funcTypeNode);
20401-
// Highlight to the end of the second to last constituent of the union
20402-
parenedFuncType.end = unionTypes[unionTypes.length - 2].end;
20403-
addRelatedInfo(diag, createDiagnosticForNode(parenedFuncType, Diagnostics.Did_you_mean_to_parenthesize_this_function_type));
20404-
}
20405-
}
20406-
}
20407-
20389+
error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
2040820390
// Return the declared type to reduce follow-on errors
2040920391
return type;
2041020392
}

tests/baselines/reference/functionTypeReturnsUnionWithUndefinedWithStrictNullChecks.errors.txt

Lines changed: 0 additions & 74 deletions
This file was deleted.

tests/baselines/reference/functionTypeReturnsUnionWithUndefinedWithStrictNullChecks.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

tests/baselines/reference/functionTypeReturnsUnionWithUndefinedWithStrictNullChecks.symbols

Lines changed: 0 additions & 89 deletions
This file was deleted.

tests/baselines/reference/functionTypeReturnsUnionWithUndefinedWithStrictNullChecks.types

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts(6,13): error TS2339: Property '#prop' does not exist on type '{}'.
2+
tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts(8,14): error TS2339: Property '#prop' does not exist on type '{}'.
3+
4+
5+
==== tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts (2 errors) ====
6+
class C {
7+
#prop = 1;
8+
9+
method(other: C) {
10+
const obj = { ...other };
11+
obj.#prop;
12+
~~~~~
13+
!!! error TS2339: Property '#prop' does not exist on type '{}'.
14+
const { ...rest } = other;
15+
rest.#prop;
16+
~~~~~
17+
!!! error TS2339: Property '#prop' does not exist on type '{}'.
18+
}
19+
}

0 commit comments

Comments
 (0)