Skip to content

Commit 7312b32

Browse files
simple test works, but too eager for generics
1 parent 421ea01 commit 7312b32

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

src/compiler/checker.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -7987,10 +7987,11 @@ namespace ts {
79877987
case SyntaxKind.JSDocNullableType:
79887988
return getTypeFromJSDocNullableTypeNode(<JSDocNullableType>node);
79897989
case SyntaxKind.JSDocNonNullableType:
7990+
return getTypeFromNonNullableType((<JSDocNullableType>node).type);
79907991
case SyntaxKind.ParenthesizedType:
79917992
case SyntaxKind.JSDocOptionalType:
79927993
case SyntaxKind.JSDocTypeExpression:
7993-
return getTypeFromTypeNode((<ParenthesizedTypeNode | JSDocTypeReferencingNode | JSDocTypeExpression>node).type);
7994+
return getTypeFromTypeNode((<ParenthesizedTypeNode | JSDocTypeReferencingNode>node).type);
79947995
case SyntaxKind.FunctionType:
79957996
case SyntaxKind.ConstructorType:
79967997
case SyntaxKind.TypeLiteral:
@@ -8016,6 +8017,10 @@ namespace ts {
80168017
}
80178018
}
80188019

8020+
function getTypeFromNonNullableType(node: TypeNode) {
8021+
return getNonNullableType(getTypeFromTypeNode(node));
8022+
}
8023+
80198024
function instantiateList<T>(items: T[], mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): T[] {
80208025
if (items && items.length) {
80218026
const result: T[] = [];

src/compiler/emitter.ts

+8
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,9 @@ namespace ts {
703703
return emitEnumMember(<EnumMember>node);
704704

705705
// JSDoc nodes (ignored)
706+
case SyntaxKind.JSDocNonNullableType:
707+
return emitNonNullType(<JSDocNonNullableType>node);
708+
706709
// Transformation nodes (ignored)
707710
}
708711

@@ -1413,6 +1416,11 @@ namespace ts {
14131416
write("!");
14141417
}
14151418

1419+
function emitNonNullType(node: JSDocNonNullableType) {
1420+
emit(node.type);
1421+
write("!");
1422+
}
1423+
14161424
function emitMetaProperty(node: MetaProperty) {
14171425
writeToken(node.keywordToken, node.pos);
14181426
write(".");
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [nonNullType.ts]
2+
let a: string | undefined | null | never;
3+
let b: typeof a!;
4+
type Assert<T> = T!;
5+
let c: Assert<typeof a>;
6+
7+
8+
//// [nonNullType.js]
9+
var a;
10+
var b;
11+
var c;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/nonNullType.ts ===
2+
let a: string | undefined | null | never;
3+
>a : Symbol(a, Decl(nonNullType.ts, 0, 3))
4+
5+
let b: typeof a!;
6+
>b : Symbol(b, Decl(nonNullType.ts, 1, 3))
7+
>a : Symbol(a, Decl(nonNullType.ts, 0, 3))
8+
9+
type Assert<T> = T!;
10+
>Assert : Symbol(Assert, Decl(nonNullType.ts, 1, 17))
11+
>T : Symbol(T, Decl(nonNullType.ts, 2, 12))
12+
>T : Symbol(T, Decl(nonNullType.ts, 2, 12))
13+
14+
let c: Assert<typeof a>;
15+
>c : Symbol(c, Decl(nonNullType.ts, 3, 3))
16+
>Assert : Symbol(Assert, Decl(nonNullType.ts, 1, 17))
17+
>a : Symbol(a, Decl(nonNullType.ts, 0, 3))
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/nonNullType.ts ===
2+
let a: string | undefined | null | never;
3+
>a : string | null | undefined
4+
>null : null
5+
6+
let b: typeof a!;
7+
>b : string
8+
>a : string | null | undefined
9+
10+
type Assert<T> = T!;
11+
>Assert : T
12+
>T : T
13+
>T : T
14+
15+
let c: Assert<typeof a>;
16+
>c : string | null | undefined
17+
>Assert : T
18+
>a : string | null | undefined
19+

tests/cases/compiler/nonNullType.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// @strictNullChecks: true
2-
type z = string | undefined | null | never;
3-
type a = string | undefined | null | never;
4-
type b = a!;
2+
let a: string | undefined | null | never;
3+
let b: typeof a!;
54
type Assert<T> = T!;
6-
type c = Assert<a>;
7-
5+
let c: Assert<typeof a>;

0 commit comments

Comments
 (0)