-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8730 from Microsoft/destructureOptionalParameter
Fix destructuring of optional parameters with --strictNullChecks
- Loading branch information
Showing
5 changed files
with
232 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//// [destructureOptionalParameter.ts] | ||
|
||
declare function f1({ a, b }?: { a: number, b: string }): void; | ||
|
||
function f2({ a, b }: { a: number, b: number } = { a: 0, b: 0 }) { | ||
a; | ||
b; | ||
} | ||
|
||
// Repro from #8681 | ||
|
||
interface Type { t: void } | ||
interface QueryMetadata { q: void } | ||
|
||
interface QueryMetadataFactory { | ||
(selector: Type | string, {descendants, read}?: { | ||
descendants?: boolean; | ||
read?: any; | ||
}): ParameterDecorator; | ||
new (selector: Type | string, {descendants, read}?: { | ||
descendants?: boolean; | ||
read?: any; | ||
}): QueryMetadata; | ||
} | ||
|
||
|
||
//// [destructureOptionalParameter.js] | ||
function f2(_a) { | ||
var _b = _a === void 0 ? { a: 0, b: 0 } : _a, a = _b.a, b = _b.b; | ||
a; | ||
b; | ||
} | ||
|
||
|
||
//// [destructureOptionalParameter.d.ts] | ||
declare function f1({a, b}?: { | ||
a: number; | ||
b: string; | ||
}): void; | ||
declare function f2({a, b}?: { | ||
a: number; | ||
b: number; | ||
}): void; | ||
interface Type { | ||
t: void; | ||
} | ||
interface QueryMetadata { | ||
q: void; | ||
} | ||
interface QueryMetadataFactory { | ||
(selector: Type | string, {descendants, read}?: { | ||
descendants?: boolean; | ||
read?: any; | ||
}): ParameterDecorator; | ||
new (selector: Type | string, {descendants, read}?: { | ||
descendants?: boolean; | ||
read?: any; | ||
}): QueryMetadata; | ||
} |
69 changes: 69 additions & 0 deletions
69
tests/baselines/reference/destructureOptionalParameter.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
=== tests/cases/compiler/destructureOptionalParameter.ts === | ||
|
||
declare function f1({ a, b }?: { a: number, b: string }): void; | ||
>f1 : Symbol(f1, Decl(destructureOptionalParameter.ts, 0, 0)) | ||
>a : Symbol(a, Decl(destructureOptionalParameter.ts, 1, 21)) | ||
>b : Symbol(b, Decl(destructureOptionalParameter.ts, 1, 24)) | ||
>a : Symbol(a, Decl(destructureOptionalParameter.ts, 1, 32)) | ||
>b : Symbol(b, Decl(destructureOptionalParameter.ts, 1, 43)) | ||
|
||
function f2({ a, b }: { a: number, b: number } = { a: 0, b: 0 }) { | ||
>f2 : Symbol(f2, Decl(destructureOptionalParameter.ts, 1, 63)) | ||
>a : Symbol(a, Decl(destructureOptionalParameter.ts, 3, 13)) | ||
>b : Symbol(b, Decl(destructureOptionalParameter.ts, 3, 16)) | ||
>a : Symbol(a, Decl(destructureOptionalParameter.ts, 3, 23)) | ||
>b : Symbol(b, Decl(destructureOptionalParameter.ts, 3, 34)) | ||
>a : Symbol(a, Decl(destructureOptionalParameter.ts, 3, 50)) | ||
>b : Symbol(b, Decl(destructureOptionalParameter.ts, 3, 56)) | ||
|
||
a; | ||
>a : Symbol(a, Decl(destructureOptionalParameter.ts, 3, 13)) | ||
|
||
b; | ||
>b : Symbol(b, Decl(destructureOptionalParameter.ts, 3, 16)) | ||
} | ||
|
||
// Repro from #8681 | ||
|
||
interface Type { t: void } | ||
>Type : Symbol(Type, Decl(destructureOptionalParameter.ts, 6, 1)) | ||
>t : Symbol(Type.t, Decl(destructureOptionalParameter.ts, 10, 16)) | ||
|
||
interface QueryMetadata { q: void } | ||
>QueryMetadata : Symbol(QueryMetadata, Decl(destructureOptionalParameter.ts, 10, 26)) | ||
>q : Symbol(QueryMetadata.q, Decl(destructureOptionalParameter.ts, 11, 25)) | ||
|
||
interface QueryMetadataFactory { | ||
>QueryMetadataFactory : Symbol(QueryMetadataFactory, Decl(destructureOptionalParameter.ts, 11, 35)) | ||
|
||
(selector: Type | string, {descendants, read}?: { | ||
>selector : Symbol(selector, Decl(destructureOptionalParameter.ts, 14, 5)) | ||
>Type : Symbol(Type, Decl(destructureOptionalParameter.ts, 6, 1)) | ||
>descendants : Symbol(descendants, Decl(destructureOptionalParameter.ts, 14, 31)) | ||
>read : Symbol(read, Decl(destructureOptionalParameter.ts, 14, 43)) | ||
|
||
descendants?: boolean; | ||
>descendants : Symbol(descendants, Decl(destructureOptionalParameter.ts, 14, 53)) | ||
|
||
read?: any; | ||
>read : Symbol(read, Decl(destructureOptionalParameter.ts, 15, 30)) | ||
|
||
}): ParameterDecorator; | ||
>ParameterDecorator : Symbol(ParameterDecorator, Decl(lib.d.ts, --, --)) | ||
|
||
new (selector: Type | string, {descendants, read}?: { | ||
>selector : Symbol(selector, Decl(destructureOptionalParameter.ts, 18, 9)) | ||
>Type : Symbol(Type, Decl(destructureOptionalParameter.ts, 6, 1)) | ||
>descendants : Symbol(descendants, Decl(destructureOptionalParameter.ts, 18, 35)) | ||
>read : Symbol(read, Decl(destructureOptionalParameter.ts, 18, 47)) | ||
|
||
descendants?: boolean; | ||
>descendants : Symbol(descendants, Decl(destructureOptionalParameter.ts, 18, 57)) | ||
|
||
read?: any; | ||
>read : Symbol(read, Decl(destructureOptionalParameter.ts, 19, 30)) | ||
|
||
}): QueryMetadata; | ||
>QueryMetadata : Symbol(QueryMetadata, Decl(destructureOptionalParameter.ts, 10, 26)) | ||
} | ||
|
72 changes: 72 additions & 0 deletions
72
tests/baselines/reference/destructureOptionalParameter.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
=== tests/cases/compiler/destructureOptionalParameter.ts === | ||
|
||
declare function f1({ a, b }?: { a: number, b: string }): void; | ||
>f1 : ({a, b}?: { a: number; b: string; } | undefined) => void | ||
>a : number | ||
>b : string | ||
>a : number | ||
>b : string | ||
|
||
function f2({ a, b }: { a: number, b: number } = { a: 0, b: 0 }) { | ||
>f2 : ({a, b}?: { a: number; b: number; }) => void | ||
>a : number | ||
>b : number | ||
>a : number | ||
>b : number | ||
>{ a: 0, b: 0 } : { a: number; b: number; } | ||
>a : number | ||
>0 : number | ||
>b : number | ||
>0 : number | ||
|
||
a; | ||
>a : number | ||
|
||
b; | ||
>b : number | ||
} | ||
|
||
// Repro from #8681 | ||
|
||
interface Type { t: void } | ||
>Type : Type | ||
>t : void | ||
|
||
interface QueryMetadata { q: void } | ||
>QueryMetadata : QueryMetadata | ||
>q : void | ||
|
||
interface QueryMetadataFactory { | ||
>QueryMetadataFactory : QueryMetadataFactory | ||
|
||
(selector: Type | string, {descendants, read}?: { | ||
>selector : Type | string | ||
>Type : Type | ||
>descendants : boolean | undefined | ||
>read : any | ||
|
||
descendants?: boolean; | ||
>descendants : boolean | undefined | ||
|
||
read?: any; | ||
>read : any | ||
|
||
}): ParameterDecorator; | ||
>ParameterDecorator : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void | ||
|
||
new (selector: Type | string, {descendants, read}?: { | ||
>selector : Type | string | ||
>Type : Type | ||
>descendants : boolean | undefined | ||
>read : any | ||
|
||
descendants?: boolean; | ||
>descendants : boolean | undefined | ||
|
||
read?: any; | ||
>read : any | ||
|
||
}): QueryMetadata; | ||
>QueryMetadata : QueryMetadata | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// @strictNullChecks: true | ||
// @declaration: true | ||
|
||
declare function f1({ a, b }?: { a: number, b: string }): void; | ||
|
||
function f2({ a, b }: { a: number, b: number } = { a: 0, b: 0 }) { | ||
a; | ||
b; | ||
} | ||
|
||
// Repro from #8681 | ||
|
||
interface Type { t: void } | ||
interface QueryMetadata { q: void } | ||
|
||
interface QueryMetadataFactory { | ||
(selector: Type | string, {descendants, read}?: { | ||
descendants?: boolean; | ||
read?: any; | ||
}): ParameterDecorator; | ||
new (selector: Type | string, {descendants, read}?: { | ||
descendants?: boolean; | ||
read?: any; | ||
}): QueryMetadata; | ||
} |