Skip to content

Commit

Permalink
simple test works, but too eager for generics
Browse files Browse the repository at this point in the history
  • Loading branch information
KiaraGrouwstra committed Aug 25, 2017
1 parent 421ea01 commit 7312b32
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7987,10 +7987,11 @@ namespace ts {
case SyntaxKind.JSDocNullableType:
return getTypeFromJSDocNullableTypeNode(<JSDocNullableType>node);
case SyntaxKind.JSDocNonNullableType:
return getTypeFromNonNullableType((<JSDocNullableType>node).type);
case SyntaxKind.ParenthesizedType:
case SyntaxKind.JSDocOptionalType:
case SyntaxKind.JSDocTypeExpression:
return getTypeFromTypeNode((<ParenthesizedTypeNode | JSDocTypeReferencingNode | JSDocTypeExpression>node).type);
return getTypeFromTypeNode((<ParenthesizedTypeNode | JSDocTypeReferencingNode>node).type);
case SyntaxKind.FunctionType:
case SyntaxKind.ConstructorType:
case SyntaxKind.TypeLiteral:
Expand All @@ -8016,6 +8017,10 @@ namespace ts {
}
}

function getTypeFromNonNullableType(node: TypeNode) {
return getNonNullableType(getTypeFromTypeNode(node));
}

function instantiateList<T>(items: T[], mapper: TypeMapper, instantiator: (item: T, mapper: TypeMapper) => T): T[] {
if (items && items.length) {
const result: T[] = [];
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,9 @@ namespace ts {
return emitEnumMember(<EnumMember>node);

// JSDoc nodes (ignored)
case SyntaxKind.JSDocNonNullableType:
return emitNonNullType(<JSDocNonNullableType>node);

// Transformation nodes (ignored)
}

Expand Down Expand Up @@ -1413,6 +1416,11 @@ namespace ts {
write("!");
}

function emitNonNullType(node: JSDocNonNullableType) {
emit(node.type);
write("!");
}

function emitMetaProperty(node: MetaProperty) {
writeToken(node.keywordToken, node.pos);
write(".");
Expand Down
11 changes: 11 additions & 0 deletions tests/baselines/reference/nonNullType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [nonNullType.ts]
let a: string | undefined | null | never;
let b: typeof a!;
type Assert<T> = T!;
let c: Assert<typeof a>;


//// [nonNullType.js]
var a;
var b;
var c;
18 changes: 18 additions & 0 deletions tests/baselines/reference/nonNullType.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
=== tests/cases/compiler/nonNullType.ts ===
let a: string | undefined | null | never;
>a : Symbol(a, Decl(nonNullType.ts, 0, 3))

let b: typeof a!;
>b : Symbol(b, Decl(nonNullType.ts, 1, 3))
>a : Symbol(a, Decl(nonNullType.ts, 0, 3))

type Assert<T> = T!;
>Assert : Symbol(Assert, Decl(nonNullType.ts, 1, 17))
>T : Symbol(T, Decl(nonNullType.ts, 2, 12))
>T : Symbol(T, Decl(nonNullType.ts, 2, 12))

let c: Assert<typeof a>;
>c : Symbol(c, Decl(nonNullType.ts, 3, 3))
>Assert : Symbol(Assert, Decl(nonNullType.ts, 1, 17))
>a : Symbol(a, Decl(nonNullType.ts, 0, 3))

19 changes: 19 additions & 0 deletions tests/baselines/reference/nonNullType.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=== tests/cases/compiler/nonNullType.ts ===
let a: string | undefined | null | never;
>a : string | null | undefined
>null : null

let b: typeof a!;
>b : string
>a : string | null | undefined

type Assert<T> = T!;
>Assert : T
>T : T
>T : T

let c: Assert<typeof a>;
>c : string | null | undefined
>Assert : T
>a : string | null | undefined

8 changes: 3 additions & 5 deletions tests/cases/compiler/nonNullType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @strictNullChecks: true
type z = string | undefined | null | never;
type a = string | undefined | null | never;
type b = a!;
let a: string | undefined | null | never;
let b: typeof a!;
type Assert<T> = T!;
type c = Assert<a>;

let c: Assert<typeof a>;

0 comments on commit 7312b32

Please sign in to comment.