Skip to content

Commit f907b50

Browse files
committed
Relax unknown checking outside of strictNullChecks a bit
1 parent 5224a6a commit f907b50

File tree

4 files changed

+10
-46
lines changed

4 files changed

+10
-46
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7783,6 +7783,7 @@ namespace ts {
77837783
t.flags & TypeFlags.ESSymbolLike ? getGlobalESSymbolType(/*reportErrors*/ languageVersion >= ScriptTarget.ES2015) :
77847784
t.flags & TypeFlags.NonPrimitive ? emptyObjectType :
77857785
t.flags & TypeFlags.Index ? keyofConstraintType :
7786+
t.flags & TypeFlags.Unknown && !strictNullChecks ? emptyObjectType :
77867787
t;
77877788
}
77887789

@@ -19501,7 +19502,7 @@ namespace ts {
1950119502
undefinedDiagnostic?: DiagnosticMessage,
1950219503
nullOrUndefinedDiagnostic?: DiagnosticMessage
1950319504
): Type {
19504-
if (type.flags & TypeFlags.Unknown) {
19505+
if (strictNullChecks && type.flags & TypeFlags.Unknown) {
1950519506
error(node, Diagnostics.Object_is_of_type_unknown);
1950619507
return errorType;
1950719508
}

tests/baselines/reference/propertyAccessOnTypeParameterWithoutConstraints.errors.txt

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

tests/baselines/reference/propertyAccessOnTypeParameterWithoutConstraints.symbols

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ var a: {
6565
}
6666
var r3: string = a().toString();
6767
>r3 : Symbol(r3, Decl(propertyAccessOnTypeParameterWithoutConstraints.ts, 20, 3))
68+
>a().toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
6869
>a : Symbol(a, Decl(propertyAccessOnTypeParameterWithoutConstraints.ts, 17, 3))
70+
>toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
6971

7072
var r3b: string = a()['toString']();
7173
>r3b : Symbol(r3b, Decl(propertyAccessOnTypeParameterWithoutConstraints.ts, 21, 3))
7274
>a : Symbol(a, Decl(propertyAccessOnTypeParameterWithoutConstraints.ts, 17, 3))
75+
>'toString' : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --))
7376

7477
var b = {
7578
>b : Symbol(b, Decl(propertyAccessOnTypeParameterWithoutConstraints.ts, 23, 3))

tests/baselines/reference/propertyAccessOnTypeParameterWithoutConstraints.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ var a: {
6666
}
6767
var r3: string = a().toString();
6868
>r3 : string
69-
>a().toString() : any
70-
>a().toString : any
69+
>a().toString() : string
70+
>a().toString : () => string
7171
>a() : unknown
7272
>a : <T>() => T
73-
>toString : any
73+
>toString : () => string
7474

7575
var r3b: string = a()['toString']();
7676
>r3b : string
77-
>a()['toString']() : any
78-
>a()['toString'] : any
77+
>a()['toString']() : string
78+
>a()['toString'] : () => string
7979
>a() : unknown
8080
>a : <T>() => T
8181
>'toString' : "toString"

0 commit comments

Comments
 (0)