Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50035,7 +50035,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const typeNode = getNonlocalEffectiveTypeAnnotationNode(parameter);
if (!typeNode) return false;
const type = getTypeFromTypeNode(typeNode);
return containsUndefinedType(type);
// allow error type here to avoid confusing errors that the annotation has to contain undefined when it does in cases like this:
//
// export function fn(x?: Unresolved | undefined): void {}
return isErrorType(type) || containsUndefinedType(type);
}

function requiresAddingImplicitUndefined(parameter: ParameterDeclaration | JSDocParameterTag, enclosingDeclaration: Node | undefined) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
isolatedDeclarationsAddUndefined2.ts(4,29): error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
isolatedDeclarationsAddUndefined2.ts(8,29): error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
isolatedDeclarationsAddUndefined2.ts(12,28): error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
isolatedDeclarationsAddUndefined2.ts(16,28): error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
isolatedDeclarationsAddUndefined2.ts(19,27): error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
isolatedDeclarationsAddUndefined2.ts(21,27): error TS2304: Cannot find name 'Unresolved'.


==== isolatedDeclarationsAddUndefined2.ts (6 errors) ====
// https://github.com/microsoft/TypeScript/issues/60123

export class Bar {
constructor(private x?: Array | undefined) {}
~~~~~
!!! error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
}

export class Bar2 {
constructor(private x?: Array) {}
~~~~~
!!! error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
}

export class Bar3 {
constructor(private x: Array | undefined) {}
~~~~~
!!! error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
}

export class Bar4 {
constructor(private x: Array) {}
~~~~~
!!! error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
}

export function test1(x?: Array | undefined): void {}
~~~~~
!!! error TS2314: Generic type 'Array<T>' requires 1 type argument(s).

export function test2(x?: Unresolved | undefined): void {}
~~~~~~~~~~
!!! error TS2304: Cannot find name 'Unresolved'.

84 changes: 84 additions & 0 deletions tests/baselines/reference/isolatedDeclarationsAddUndefined2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//// [tests/cases/compiler/isolatedDeclarationsAddUndefined2.ts] ////

//// [isolatedDeclarationsAddUndefined2.ts]
// https://github.com/microsoft/TypeScript/issues/60123

export class Bar {
constructor(private x?: Array | undefined) {}
}

export class Bar2 {
constructor(private x?: Array) {}
}

export class Bar3 {
constructor(private x: Array | undefined) {}
}

export class Bar4 {
constructor(private x: Array) {}
}

export function test1(x?: Array | undefined): void {}

export function test2(x?: Unresolved | undefined): void {}


//// [isolatedDeclarationsAddUndefined2.js]
"use strict";
// https://github.com/microsoft/TypeScript/issues/60123
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bar4 = exports.Bar3 = exports.Bar2 = exports.Bar = void 0;
exports.test1 = test1;
exports.test2 = test2;
var Bar = /** @class */ (function () {
function Bar(x) {
this.x = x;
}
return Bar;
}());
exports.Bar = Bar;
var Bar2 = /** @class */ (function () {
function Bar2(x) {
this.x = x;
}
return Bar2;
}());
exports.Bar2 = Bar2;
var Bar3 = /** @class */ (function () {
function Bar3(x) {
this.x = x;
}
return Bar3;
}());
exports.Bar3 = Bar3;
var Bar4 = /** @class */ (function () {
function Bar4(x) {
this.x = x;
}
return Bar4;
}());
exports.Bar4 = Bar4;
function test1(x) { }
function test2(x) { }


//// [isolatedDeclarationsAddUndefined2.d.ts]
export declare class Bar {
private x?;
constructor(x?: Array | undefined);
}
export declare class Bar2 {
private x?;
constructor(x?: Array);
}
export declare class Bar3 {
private x;
constructor(x: Array | undefined);
}
export declare class Bar4 {
private x;
constructor(x: Array);
}
export declare function test1(x?: Array | undefined): void;
export declare function test2(x?: Unresolved | undefined): void;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//// [tests/cases/compiler/isolatedDeclarationsAddUndefined2.ts] ////

=== isolatedDeclarationsAddUndefined2.ts ===
// https://github.com/microsoft/TypeScript/issues/60123

export class Bar {
>Bar : Symbol(Bar, Decl(isolatedDeclarationsAddUndefined2.ts, 0, 0))

constructor(private x?: Array | undefined) {}
>x : Symbol(Bar.x, Decl(isolatedDeclarationsAddUndefined2.ts, 3, 16))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
}

export class Bar2 {
>Bar2 : Symbol(Bar2, Decl(isolatedDeclarationsAddUndefined2.ts, 4, 1))

constructor(private x?: Array) {}
>x : Symbol(Bar2.x, Decl(isolatedDeclarationsAddUndefined2.ts, 7, 16))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
}

export class Bar3 {
>Bar3 : Symbol(Bar3, Decl(isolatedDeclarationsAddUndefined2.ts, 8, 1))

constructor(private x: Array | undefined) {}
>x : Symbol(Bar3.x, Decl(isolatedDeclarationsAddUndefined2.ts, 11, 16))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
}

export class Bar4 {
>Bar4 : Symbol(Bar4, Decl(isolatedDeclarationsAddUndefined2.ts, 12, 1))

constructor(private x: Array) {}
>x : Symbol(Bar4.x, Decl(isolatedDeclarationsAddUndefined2.ts, 15, 16))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
}

export function test1(x?: Array | undefined): void {}
>test1 : Symbol(test1, Decl(isolatedDeclarationsAddUndefined2.ts, 16, 1))
>x : Symbol(x, Decl(isolatedDeclarationsAddUndefined2.ts, 18, 22))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

export function test2(x?: Unresolved | undefined): void {}
>test2 : Symbol(test2, Decl(isolatedDeclarationsAddUndefined2.ts, 18, 53))
>x : Symbol(x, Decl(isolatedDeclarationsAddUndefined2.ts, 20, 22))
>Unresolved : Symbol(Unresolved)

53 changes: 53 additions & 0 deletions tests/baselines/reference/isolatedDeclarationsAddUndefined2.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//// [tests/cases/compiler/isolatedDeclarationsAddUndefined2.ts] ////

=== isolatedDeclarationsAddUndefined2.ts ===
// https://github.com/microsoft/TypeScript/issues/60123

export class Bar {
>Bar : Bar
> : ^^^

constructor(private x?: Array | undefined) {}
>x : any
> : ^^^
}

export class Bar2 {
>Bar2 : Bar2
> : ^^^^

constructor(private x?: Array) {}
>x : any
> : ^^^
}

export class Bar3 {
>Bar3 : Bar3
> : ^^^^

constructor(private x: Array | undefined) {}
>x : any
> : ^^^
}

export class Bar4 {
>Bar4 : Bar4
> : ^^^^

constructor(private x: Array) {}
>x : any
> : ^^^
}

export function test1(x?: Array | undefined): void {}
>test1 : (x?: Array | undefined) => void
> : ^ ^^^ ^^^^^
>x : any
> : ^^^

export function test2(x?: Unresolved | undefined): void {}
>test2 : (x?: Unresolved | undefined) => void
> : ^ ^^^ ^^^^^
>x : any
> : ^^^

25 changes: 25 additions & 0 deletions tests/cases/compiler/isolatedDeclarationsAddUndefined2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @isolatedDeclarations: true
// @declaration: true
// @strict: true

// https://github.com/microsoft/TypeScript/issues/60123

export class Bar {
constructor(private x?: Array | undefined) {}
}

export class Bar2 {
constructor(private x?: Array) {}
}

export class Bar3 {
constructor(private x: Array | undefined) {}
}

export class Bar4 {
constructor(private x: Array) {}
}

export function test1(x?: Array | undefined): void {}

export function test2(x?: Unresolved | undefined): void {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function test2(x?: Unresolved | undefined): void {}
export function test2(x?: Unresolved | undefined): void {}
export function test3(x?: Unresolved): void {}

Maybe this extra test would be valuable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, i just pushed it out