From 18e1ac030613bd15a55156bd95e16b5002e99ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Ginth=C3=B6r?= <26004708+Lazarus535@users.noreply.github.com> Date: Mon, 22 Jan 2018 09:52:58 +0100 Subject: [PATCH 1/4] Fixes #17080 Changes are in src/compiler.checker.ts only The second arguments to the function "removeOptionalityFromDeclaredType" has been changed from "getRootDeclaration(declaration)" to "declaration". --- pull_request_template.md | 9 +- src/compiler/checker.ts | 2 +- ...rInDestructuringWithInitializer.errors.txt | 62 ++++++ ...ParameterInDestructuringWithInitializer.js | 80 +++++++ ...eterInDestructuringWithInitializer.symbols | 154 ++++++++++++++ ...ameterInDestructuringWithInitializer.types | 198 ++++++++++++++++++ ...ParameterInDestructuringWithInitializer.ts | 39 ++++ 7 files changed, 539 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt create mode 100644 tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js create mode 100644 tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols create mode 100644 tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types create mode 100644 tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts diff --git a/pull_request_template.md b/pull_request_template.md index 2c49c84641b..faa484054be 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -2,15 +2,16 @@ Thank you for submitting a pull request! Here's a checklist you might find useful. -[ ] There is an associated issue that is labelled +[X] There is an associated issue that is labelled 'Bug' or 'help wanted' or is in the Community milestone -[ ] Code is up-to-date with the `master` branch -[ ] You've successfully run `jake runtests` locally +[X] Code is up-to-date with the `master` branch +[X] You've successfully run `jake runtests` locally [ ] You've signed the CLA -[ ] There are new or updated unit tests validating the change +[X] There are new or updated unit tests validating the change Refer to CONTRIBUTING.MD for more details. https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md --> Fixes # +#17080 diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 405fd11f138..74c60bcdb62 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13046,7 +13046,7 @@ namespace ts { node.parent.kind === SyntaxKind.NonNullExpression || declaration.kind === SyntaxKind.VariableDeclaration && (declaration).exclamationToken || declaration.flags & NodeFlags.Ambient; - const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, getRootDeclaration(declaration) as VariableLikeDeclaration) : type) : + const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, declaration as VariableLikeDeclaration) : type) : type === autoType || type === autoArrayType ? undefinedType : getOptionalType(type); const flowType = getFlowTypeOfReference(node, type, initialType, flowContainer, !assumeInitialized); diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt new file mode 100644 index 00000000000..14bc3ea8e6c --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt @@ -0,0 +1,62 @@ +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(6,8): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(16,7): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(21,7): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. + + +==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (4 errors) ==== + // https://github.com/Microsoft/TypeScript/issues/17080 + function f(a:number,b:number) { + } + + function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { + f(a, b) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { + f(a, b) + // no error + } + + function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { + f(a,b) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b,c) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b, c) + // no error + } + + function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { + f(b, c) + ~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + // error + } + + function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { + f(b, c) + // no error + } + \ No newline at end of file diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js new file mode 100644 index 00000000000..8c297088f14 --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js @@ -0,0 +1,80 @@ +//// [optionalParameterInDestructuringWithInitializer.ts] +// https://github.com/Microsoft/TypeScript/issues/17080 +function f(a:number,b:number) { +} + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { + f(a, b) + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { + f(a, b) + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { + f(a,b) + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b,c) + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b, c) + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { + f(b, c) + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { + f(b, c) + // no error +} + + +//// [optionalParameterInDestructuringWithInitializer.js] +// https://github.com/Microsoft/TypeScript/issues/17080 +function f(a, b) { +} +function func1(_a) { + var _b = _a === void 0 ? { a: 1, b: 2 } : _a, a = _b.a, b = _b.b; + f(a, b); + // error +} +function func2(_a) { + var _b = _a === void 0 ? { a: 1, b: 2 } : _a, a = _b.a, _c = _b.b, b = _c === void 0 ? 3 : _c; + f(a, b); + // no error +} +function func3(_a) { + var _b = _a === void 0 ? { a: 1 } : _a, a = _b.a, b = _b.b; + f(a, b); + // error +} +function func4(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, b = _c.b, c = _c.c, d = _b.d; + f(b, c); + // error +} +function func5(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, b = _c.b, _d = _c.c, c = _d === void 0 ? 4 : _d, d = _b.d; + f(b, c); + // no error +} +function func6(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, _d = _c === void 0 ? { b: 4, c: 5 } : _c, b = _d.b, c = _d.c, d = _b.d; + f(b, c); + // error +} +function func7(_a) { + var _b = _a === void 0 ? { a: { b: 1, c: 2 }, d: 3 } : _a, _c = _b.a, _d = _c === void 0 ? { b: 4, c: 5 } : _c, b = _d.b, _e = _d.c, c = _e === void 0 ? 6 : _e, d = _b.d; + f(b, c); + // no error +} diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols new file mode 100644 index 00000000000..fc068a0babb --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols @@ -0,0 +1,154 @@ +=== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts === +// https://github.com/Microsoft/TypeScript/issues/17080 +function f(a:number,b:number) { +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 1, 11)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 1, 20)) +} + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { +>func1 : Symbol(func1, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 19)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 25)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 35)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 51)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 56)) + + f(a, b) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 19)) + + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { +>func2 : Symbol(func2, Decl(optionalParameterInDestructuringWithInitializer.ts, 7, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 19)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 29)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 39)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 54)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 59)) + + f(a, b) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 9, 19)) + + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { +>func3 : Symbol(func3, Decl(optionalParameterInDestructuringWithInitializer.ts, 12, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 19)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 25)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 35)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 51)) + + f(a,b) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 17)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 14, 19)) + + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func4 : Symbol(func4, Decl(optionalParameterInDestructuringWithInitializer.ts, 17, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 33)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 23)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 27)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 33)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 37)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 47)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 59)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 73)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 77)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 82)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 88)) + + f(b,c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 19, 23)) + + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func5 : Symbol(func5, Decl(optionalParameterInDestructuringWithInitializer.ts, 22, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 36)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 20)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 22)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 30)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 36)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 40)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 50)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 62)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 76)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 80)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 85)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 91)) + + f(b, c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 20)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 24, 22)) + + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { +>func6 : Symbol(func6, Decl(optionalParameterInDestructuringWithInitializer.ts, 27, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 48)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 23)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 30)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 35)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 42)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 48)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 52)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 62)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 75)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 90)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 94)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 99)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 105)) + + f(b, c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 29, 23)) + + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { +>func7 : Symbol(func7, Decl(optionalParameterInDestructuringWithInitializer.ts, 32, 1)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 52)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 23)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 34)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 39)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 46)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 52)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 56)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 66)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 79)) +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 94)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 98)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 103)) +>d : Symbol(d, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 110)) + + f(b, c) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 21)) +>c : Symbol(c, Decl(optionalParameterInDestructuringWithInitializer.ts, 34, 23)) + + // no error +} + diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types new file mode 100644 index 00000000000..8def19dde20 --- /dev/null +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types @@ -0,0 +1,198 @@ +=== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts === +// https://github.com/Microsoft/TypeScript/issues/17080 +function f(a:number,b:number) { +>f : (a: number, b: number) => void +>a : number +>b : number +} + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { +>func1 : ({ a, b }?: { a: number; b?: number | undefined; }) => void +>a : number +>b : number | undefined +>a : number +>b : number | undefined +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + + f(a, b) +>f(a, b) : void +>f : (a: number, b: number) => void +>a : number +>b : number | undefined + + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { +>func2 : ({ a, b }?: { a: number; b?: number | undefined; }) => void +>a : number +>b : number +>3 : 3 +>a : number +>b : number | undefined +>{a: 1,b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + + f(a, b) +>f(a, b) : void +>f : (a: number, b: number) => void +>a : number +>b : number + + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { +>func3 : ({ a, b }?: { a: number; b?: number | undefined; }) => void +>a : number +>b : number | undefined +>a : number +>b : number | undefined +>{a: 1} : { a: number; } +>a : number +>1 : 1 + + f(a,b) +>f(a,b) : void +>f : (a: number, b: number) => void +>a : number +>b : number | undefined + + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func4 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number | undefined +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1,c: 2},d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1,c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b,c) +>f(b,c) : void +>f : (a: number, b: number) => void +>b : number +>c : number | undefined + + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { +>func5 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number +>4 : 4 +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1,c: 2},d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1,c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b, c) +>f(b, c) : void +>f : (a: number, b: number) => void +>b : number +>c : number + + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { +>func6 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number | undefined +>{b: 4, c: 5} : { b: number; c: number; } +>b : number +>4 : 4 +>c : number +>5 : 5 +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1,c: 2}, d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1,c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b, c) +>f(b, c) : void +>f : (a: number, b: number) => void +>b : number +>c : number | undefined + + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { +>func7 : ({ a: { b, c }, d }?: { a: { b: number; c?: number | undefined; }; d: number; }) => void +>a : any +>b : number +>c : number +>6 : 6 +>{b: 4, c: 5} : { b: number; c?: number; } +>b : number +>4 : 4 +>c : number +>5 : 5 +>d : number +>a : { b: number; c?: number | undefined; } +>b : number +>c : number | undefined +>d : number +>{a: {b: 1, c: 2}, d: 3} : { a: { b: number; c: number; }; d: number; } +>a : { b: number; c: number; } +>{b: 1, c: 2} : { b: number; c: number; } +>b : number +>1 : 1 +>c : number +>2 : 2 +>d : number +>3 : 3 + + f(b, c) +>f(b, c) : void +>f : (a: number, b: number) => void +>b : number +>c : number + + // no error +} + diff --git a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts new file mode 100644 index 00000000000..3666ee2d954 --- /dev/null +++ b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts @@ -0,0 +1,39 @@ +// @strictNullChecks: true +// https://github.com/Microsoft/TypeScript/issues/17080 +function f(a:number,b:number) { +} + +function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { + f(a, b) + // error +} + +function func2( {a, b = 3}: {a: number, b?:number} = {a: 1,b: 2} ) { + f(a, b) + // no error +} + +function func3( {a, b}: {a: number, b?: number} = {a: 1} ) { + f(a,b) + // error +} + +function func4( {a: {b, c}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b,c) + // error +} + +function func5({a: {b, c = 4}, d}: {a: {b: number,c?: number},d: number} = {a: {b: 1,c: 2},d: 3} ) { + f(b, c) + // no error +} + +function func6( {a: {b, c} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1,c: 2}, d: 3} ) { + f(b, c) + // error +} + +function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, d: number} = {a: {b: 1, c: 2}, d: 3} ) { + f(b, c) + // no error +} From 5a87a94c59a7ea137113a873b163c98e7322fa81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Ginth=C3=B6r?= <26004708+Lazarus535@users.noreply.github.com> Date: Mon, 22 Jan 2018 13:40:57 +0100 Subject: [PATCH 2/4] Fixes #17080 https://github.com/Microsoft/TypeScript/issues/17080 Added testcases from the Github bugreport (all working as intended now). Signed CLA. --- pull_request_template.md | 2 +- ...rInDestructuringWithInitializer.errors.txt | 38 ++++++++++- ...ParameterInDestructuringWithInitializer.js | 44 +++++++++++++ ...eterInDestructuringWithInitializer.symbols | 55 ++++++++++++++++ ...ameterInDestructuringWithInitializer.types | 66 +++++++++++++++++++ ...ParameterInDestructuringWithInitializer.ts | 26 ++++++++ 6 files changed, 229 insertions(+), 2 deletions(-) diff --git a/pull_request_template.md b/pull_request_template.md index faa484054be..4243c2f671f 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -6,7 +6,7 @@ Here's a checklist you might find useful. 'Bug' or 'help wanted' or is in the Community milestone [X] Code is up-to-date with the `master` branch [X] You've successfully run `jake runtests` locally -[ ] You've signed the CLA +[X] You've signed the CLA [X] There are new or updated unit tests validating the change Refer to CONTRIBUTING.MD for more details. diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt index 14bc3ea8e6c..8965d7172e8 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt @@ -6,9 +6,13 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(21,7): e Type 'undefined' is not assignable to type 'number'. tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(45,10): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. + Type 'undefined' is not assignable to type 'number'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(55,11): error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'. + Type 'null' is not assignable to type 'number | undefined'. -==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (4 errors) ==== +==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (6 errors) ==== // https://github.com/Microsoft/TypeScript/issues/17080 function f(a:number,b:number) { } @@ -59,4 +63,36 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): e f(b, c) // no error } + + interface Foo { + readonly bar?: number; + } + + function performFoo({ bar }: Foo = {}) { + useBar(bar); + ~~~ +!!! error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'undefined' is not assignable to type 'number'. + } + + function useBar(bar: number) { + f(bar, 1) + } + + performFoo(); + + function performFoo2({ bar = null }: Foo = {}) { + useBar2(bar); + ~~~ +!!! error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'. +!!! error TS2345: Type 'null' is not assignable to type 'number | undefined'. + } + + function useBar2(bar: number | undefined) { + if (bar) { + f(bar, 1) + } + } + + performFoo2(); \ No newline at end of file diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js index 8c297088f14..cb929d89112 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js @@ -37,6 +37,32 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, f(b, c) // no error } + +interface Foo { + readonly bar?: number; +} + +function performFoo({ bar }: Foo = {}) { + useBar(bar); +} + +function useBar(bar: number) { + f(bar, 1) +} + +performFoo(); + +function performFoo2({ bar = null }: Foo = {}) { + useBar2(bar); +} + +function useBar2(bar: number | undefined) { + if (bar) { + f(bar, 1) + } +} + +performFoo2(); //// [optionalParameterInDestructuringWithInitializer.js] @@ -78,3 +104,21 @@ function func7(_a) { f(b, c); // no error } +function performFoo(_a) { + var bar = (_a === void 0 ? {} : _a).bar; + useBar(bar); +} +function useBar(bar) { + f(bar, 1); +} +performFoo(); +function performFoo2(_a) { + var _b = (_a === void 0 ? {} : _a).bar, bar = _b === void 0 ? null : _b; + useBar2(bar); +} +function useBar2(bar) { + if (bar) { + f(bar, 1); + } +} +performFoo2(); diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols index fc068a0babb..399956476c8 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols @@ -152,3 +152,58 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, // no error } +interface Foo { +>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) + + readonly bar?: number; +>bar : Symbol(Foo.bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 39, 15)) +} + +function performFoo({ bar }: Foo = {}) { +>performFoo : Symbol(performFoo, Decl(optionalParameterInDestructuringWithInitializer.ts, 41, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 43, 21)) +>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) + + useBar(bar); +>useBar : Symbol(useBar, Decl(optionalParameterInDestructuringWithInitializer.ts, 45, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 43, 21)) +} + +function useBar(bar: number) { +>useBar : Symbol(useBar, Decl(optionalParameterInDestructuringWithInitializer.ts, 45, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 16)) + + f(bar, 1) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 16)) +} + +performFoo(); +>performFoo : Symbol(performFoo, Decl(optionalParameterInDestructuringWithInitializer.ts, 41, 1)) + +function performFoo2({ bar = null }: Foo = {}) { +>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 13)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 22)) +>Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) + + useBar2(bar); +>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 22)) +} + +function useBar2(bar: number | undefined) { +>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) + + if (bar) { +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) + + f(bar, 1) +>f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) + } +} + +performFoo2(); +>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 13)) + diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types index 8def19dde20..1d1618e12e3 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types @@ -196,3 +196,69 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, // no error } +interface Foo { +>Foo : Foo + + readonly bar?: number; +>bar : number | undefined +} + +function performFoo({ bar }: Foo = {}) { +>performFoo : ({ bar }?: Foo) => void +>bar : number | undefined +>Foo : Foo +>{} : {} + + useBar(bar); +>useBar(bar) : void +>useBar : (bar: number) => void +>bar : number | undefined +} + +function useBar(bar: number) { +>useBar : (bar: number) => void +>bar : number + + f(bar, 1) +>f(bar, 1) : void +>f : (a: number, b: number) => void +>bar : number +>1 : 1 +} + +performFoo(); +>performFoo() : void +>performFoo : ({ bar }?: Foo) => void + +function performFoo2({ bar = null }: Foo = {}) { +>performFoo2 : ({ bar }?: Foo) => void +>bar : number | null +>null : null +>Foo : Foo +>{} : {} + + useBar2(bar); +>useBar2(bar) : void +>useBar2 : (bar: number | undefined) => void +>bar : number | null +} + +function useBar2(bar: number | undefined) { +>useBar2 : (bar: number | undefined) => void +>bar : number | undefined + + if (bar) { +>bar : number | undefined + + f(bar, 1) +>f(bar, 1) : void +>f : (a: number, b: number) => void +>bar : number +>1 : 1 + } +} + +performFoo2(); +>performFoo2() : void +>performFoo2 : ({ bar }?: Foo) => void + diff --git a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts index 3666ee2d954..1f1847a19a7 100644 --- a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts +++ b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts @@ -37,3 +37,29 @@ function func7( {a: {b, c = 6} = {b: 4, c: 5}, d}: {a: {b: number, c?: number}, f(b, c) // no error } + +interface Foo { + readonly bar?: number; +} + +function performFoo({ bar }: Foo = {}) { + useBar(bar); +} + +function useBar(bar: number) { + f(bar, 1) +} + +performFoo(); + +function performFoo2({ bar = null }: Foo = {}) { + useBar2(bar); +} + +function useBar2(bar: number | undefined) { + if (bar) { + f(bar, 1) + } +} + +performFoo2(); From d11341820e3aa3d99c918700a113f2819d8c381e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Ginth=C3=B6r?= <26004708+Lazarus535@users.noreply.github.com> Date: Mon, 22 Jan 2018 21:45:37 +0100 Subject: [PATCH 3/4] Fixes #17080 Fixed the two requested changes. 1) Deleting the file "pull_request_template.md" 2) Declaring functions in tests, instead of defining --- pull_request_template.md | 17 ------- ...rInDestructuringWithInitializer.errors.txt | 16 +++---- ...ParameterInDestructuringWithInitializer.js | 24 ++-------- ...eterInDestructuringWithInitializer.symbols | 44 +++++++------------ ...ameterInDestructuringWithInitializer.types | 26 ++--------- ...ParameterInDestructuringWithInitializer.ts | 14 ++---- 6 files changed, 32 insertions(+), 109 deletions(-) delete mode 100644 pull_request_template.md diff --git a/pull_request_template.md b/pull_request_template.md deleted file mode 100644 index 4243c2f671f..00000000000 --- a/pull_request_template.md +++ /dev/null @@ -1,17 +0,0 @@ - - -Fixes # -#17080 diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt index 8965d7172e8..b2fea589cb1 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.errors.txt @@ -8,14 +8,14 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(31,8): e Type 'undefined' is not assignable to type 'number'. tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(45,10): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. Type 'undefined' is not assignable to type 'number'. -tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(55,11): error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'. +tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(53,11): error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'number | undefined'. Type 'null' is not assignable to type 'number | undefined'. ==== tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts (6 errors) ==== // https://github.com/Microsoft/TypeScript/issues/17080 - function f(a:number,b:number) { - } + + declare function f(a:number,b:number): void; function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { f(a, b) @@ -75,9 +75,7 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(55,11): !!! error TS2345: Type 'undefined' is not assignable to type 'number'. } - function useBar(bar: number) { - f(bar, 1) - } + declare function useBar(bar: number): void; performFoo(); @@ -88,11 +86,7 @@ tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts(55,11): !!! error TS2345: Type 'null' is not assignable to type 'number | undefined'. } - function useBar2(bar: number | undefined) { - if (bar) { - f(bar, 1) - } - } + declare function useBar2(bar: number | undefined): void; performFoo2(); \ No newline at end of file diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js index cb929d89112..642f00a4f50 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.js @@ -1,7 +1,7 @@ //// [optionalParameterInDestructuringWithInitializer.ts] // https://github.com/Microsoft/TypeScript/issues/17080 -function f(a:number,b:number) { -} + +declare function f(a:number,b:number): void; function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { f(a, b) @@ -46,9 +46,7 @@ function performFoo({ bar }: Foo = {}) { useBar(bar); } -function useBar(bar: number) { - f(bar, 1) -} +declare function useBar(bar: number): void; performFoo(); @@ -56,19 +54,13 @@ function performFoo2({ bar = null }: Foo = {}) { useBar2(bar); } -function useBar2(bar: number | undefined) { - if (bar) { - f(bar, 1) - } -} +declare function useBar2(bar: number | undefined): void; performFoo2(); //// [optionalParameterInDestructuringWithInitializer.js] // https://github.com/Microsoft/TypeScript/issues/17080 -function f(a, b) { -} function func1(_a) { var _b = _a === void 0 ? { a: 1, b: 2 } : _a, a = _b.a, b = _b.b; f(a, b); @@ -108,17 +100,9 @@ function performFoo(_a) { var bar = (_a === void 0 ? {} : _a).bar; useBar(bar); } -function useBar(bar) { - f(bar, 1); -} performFoo(); function performFoo2(_a) { var _b = (_a === void 0 ? {} : _a).bar, bar = _b === void 0 ? null : _b; useBar2(bar); } -function useBar2(bar) { - if (bar) { - f(bar, 1); - } -} performFoo2(); diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols index 399956476c8..6d4cf484d92 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.symbols @@ -1,13 +1,13 @@ === tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts === // https://github.com/Microsoft/TypeScript/issues/17080 -function f(a:number,b:number) { + +declare function f(a:number,b:number): void; >f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) ->a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 1, 11)) ->b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 1, 20)) -} +>a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 19)) +>b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 28)) function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { ->func1 : Symbol(func1, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 1)) +>func1 : Symbol(func1, Decl(optionalParameterInDestructuringWithInitializer.ts, 2, 44)) >a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 17)) >b : Symbol(b, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 19)) >a : Symbol(a, Decl(optionalParameterInDestructuringWithInitializer.ts, 4, 25)) @@ -169,41 +169,27 @@ function performFoo({ bar }: Foo = {}) { >bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 43, 21)) } -function useBar(bar: number) { +declare function useBar(bar: number): void; >useBar : Symbol(useBar, Decl(optionalParameterInDestructuringWithInitializer.ts, 45, 1)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 16)) - - f(bar, 1) ->f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 16)) -} +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 47, 24)) performFoo(); >performFoo : Symbol(performFoo, Decl(optionalParameterInDestructuringWithInitializer.ts, 41, 1)) function performFoo2({ bar = null }: Foo = {}) { ->performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 13)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 22)) +>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 49, 13)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 22)) >Foo : Symbol(Foo, Decl(optionalParameterInDestructuringWithInitializer.ts, 37, 1)) useBar2(bar); ->useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 1)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 22)) +>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 22)) } -function useBar2(bar: number | undefined) { ->useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 1)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) - - if (bar) { ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) - - f(bar, 1) ->f : Symbol(f, Decl(optionalParameterInDestructuringWithInitializer.ts, 0, 0)) ->bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 57, 17)) - } -} +declare function useBar2(bar: number | undefined): void; +>useBar2 : Symbol(useBar2, Decl(optionalParameterInDestructuringWithInitializer.ts, 53, 1)) +>bar : Symbol(bar, Decl(optionalParameterInDestructuringWithInitializer.ts, 55, 25)) performFoo2(); ->performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 51, 13)) +>performFoo2 : Symbol(performFoo2, Decl(optionalParameterInDestructuringWithInitializer.ts, 49, 13)) diff --git a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types index 1d1618e12e3..26110e71051 100644 --- a/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types +++ b/tests/baselines/reference/optionalParameterInDestructuringWithInitializer.types @@ -1,10 +1,10 @@ === tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts === // https://github.com/Microsoft/TypeScript/issues/17080 -function f(a:number,b:number) { + +declare function f(a:number,b:number): void; >f : (a: number, b: number) => void >a : number >b : number -} function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { >func1 : ({ a, b }?: { a: number; b?: number | undefined; }) => void @@ -215,17 +215,10 @@ function performFoo({ bar }: Foo = {}) { >bar : number | undefined } -function useBar(bar: number) { +declare function useBar(bar: number): void; >useBar : (bar: number) => void >bar : number - f(bar, 1) ->f(bar, 1) : void ->f : (a: number, b: number) => void ->bar : number ->1 : 1 -} - performFoo(); >performFoo() : void >performFoo : ({ bar }?: Foo) => void @@ -243,21 +236,10 @@ function performFoo2({ bar = null }: Foo = {}) { >bar : number | null } -function useBar2(bar: number | undefined) { +declare function useBar2(bar: number | undefined): void; >useBar2 : (bar: number | undefined) => void >bar : number | undefined - if (bar) { ->bar : number | undefined - - f(bar, 1) ->f(bar, 1) : void ->f : (a: number, b: number) => void ->bar : number ->1 : 1 - } -} - performFoo2(); >performFoo2() : void >performFoo2 : ({ bar }?: Foo) => void diff --git a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts index 1f1847a19a7..d3ebd99efa1 100644 --- a/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts +++ b/tests/cases/compiler/optionalParameterInDestructuringWithInitializer.ts @@ -1,7 +1,7 @@ // @strictNullChecks: true // https://github.com/Microsoft/TypeScript/issues/17080 -function f(a:number,b:number) { -} + +declare function f(a:number,b:number): void; function func1( {a, b}: {a: number, b?: number} = {a: 1, b: 2} ) { f(a, b) @@ -46,9 +46,7 @@ function performFoo({ bar }: Foo = {}) { useBar(bar); } -function useBar(bar: number) { - f(bar, 1) -} +declare function useBar(bar: number): void; performFoo(); @@ -56,10 +54,6 @@ function performFoo2({ bar = null }: Foo = {}) { useBar2(bar); } -function useBar2(bar: number | undefined) { - if (bar) { - f(bar, 1) - } -} +declare function useBar2(bar: number | undefined): void; performFoo2(); From 7b449a5e6230b5ec9445902a87148a698719baa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Ginth=C3=B6r?= <26004708+Lazarus535@users.noreply.github.com> Date: Mon, 22 Jan 2018 22:09:35 +0100 Subject: [PATCH 4/4] Fixes #17080 Readded untouched pull_request_template.md --- pull_request_template.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 pull_request_template.md diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 00000000000..2c49c84641b --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,16 @@ + + +Fixes #