From 01a9e4f9be4eeebb1eb45350f6e55557035d7e38 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 26 Jan 2017 12:01:27 -0800 Subject: [PATCH] isOptionalParameter says unused IIFE arguments are optional Related to adding undefined, though not strictly the same, this change adds '?' to unused IIFE parameters in quick info. --- src/compiler/checker.ts | 8 +++++++- tests/baselines/reference/contextuallyTypedIife.types | 8 ++++---- tests/cases/fourslash/quickInfoDisplayPartsIife.ts | 5 +++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsIife.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 22db0d32767..34d71a0ab6e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5145,6 +5145,12 @@ namespace ts { Debug.assert(parameterIndex >= 0); return parameterIndex >= signature.minArgumentCount; } + const iife = getImmediatelyInvokedFunctionExpression(node.parent); + if (iife) { + return !node.type && + !node.dotDotDotToken && + indexOf((node.parent as SignatureDeclaration).parameters, node) >= iife.arguments.length; + } return false; } @@ -14026,7 +14032,7 @@ namespace ts { return getTypeOfSymbol(symbol); } } - + function getTypeAtPosition(signature: Signature, pos: number): Type { return signature.hasRestParameter ? pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) : diff --git a/tests/baselines/reference/contextuallyTypedIife.types b/tests/baselines/reference/contextuallyTypedIife.types index 15038e7dd26..676755fb341 100644 --- a/tests/baselines/reference/contextuallyTypedIife.types +++ b/tests/baselines/reference/contextuallyTypedIife.types @@ -253,8 +253,8 @@ let eleven = (o => o.a(11))({ a: function(n) { return n; } }); // missing arguments (function(x, undefined) { return x; })(42); >(function(x, undefined) { return x; })(42) : number ->(function(x, undefined) { return x; }) : (x: number, undefined: any) => number ->function(x, undefined) { return x; } : (x: number, undefined: any) => number +>(function(x, undefined) { return x; }) : (x: number, undefined?: any) => number +>function(x, undefined) { return x; } : (x: number, undefined?: any) => number >x : number >undefined : any >x : number @@ -262,8 +262,8 @@ let eleven = (o => o.a(11))({ a: function(n) { return n; } }); ((x, y, z) => 42)(); >((x, y, z) => 42)() : number ->((x, y, z) => 42) : (x: any, y: any, z: any) => number ->(x, y, z) => 42 : (x: any, y: any, z: any) => number +>((x, y, z) => 42) : (x?: any, y?: any, z?: any) => number +>(x, y, z) => 42 : (x?: any, y?: any, z?: any) => number >x : any >y : any >z : any diff --git a/tests/cases/fourslash/quickInfoDisplayPartsIife.ts b/tests/cases/fourslash/quickInfoDisplayPartsIife.ts new file mode 100644 index 00000000000..e4ce2bf96e3 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsIife.ts @@ -0,0 +1,5 @@ +/// +// @strictNullChecks: true +////var iife = (function foo/*1*/(x, y) { return x })(12); + +verify.quickInfoAt('1', '(local function) foo(x: number, y?: undefined): number');