-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properties retrieved via destructuring do not mark that property as being used #11324
Comments
* Use a single ShimMap class, and indicate that iteration always yields string keys (which it did before too) * Remove emacs-added newline at end of baseline * Remove space at end of line in baseline * Add numeric indexer to strings and remove lint * Update baselines with spread string's numeric indexers * Reset baseline line number to the locally incorrect value * Remove trailing newline from baseline again * Respond to PR comments * Refactor getTypeFromTypeLiteral, from PR comments * Fix lint * Use same literal comparison rules for switch/=== switch was missing the rule for converting literal types to the literal base type if needed. * Add switch comparability test and update baselines * Push eitherIsNotLiteral check into isTypeEqualityComparableTo Since all callers need this check -- it's how equality is supposed to work everywhere. * Update baselines There are more literal types in error messages because error reporting no longer has the advantage of calls to getBaseLiteralType * Adds ES5 to ES3 transformer for reserved words * Minor cleanup * Cleaned up emit of enum declaration * Return both ts and js results from module resolution, and don't have moduleNameResolver responsible for omitting files based on compiler options * Instead of getResolutionOrDiagnostic, use getResolutionDiagnostic and avoid using resolution.resolvedFileName if the diagnostic is defined. * Remove "ResolvedModuleFromHost" type and just make `resolvedTsFileName` and `resolvedJsFileName` optional properties (but still automatically infer one of them to supply if the host supplied neither) * Remove type inference for spread types * Update inference test for spread types * Make spread assignability and apparent type stricter Assignability now does not allow properties to the left of a type parameter. Apparent type now only returns the apparent type of the right-most spread member. * Update tests w/spread assignability+apparent type * Moved AMD/CJS/UMD transform to end * Spread no longer distributes intersections * Update spread w/intersection tests * Move System module transform to end. * Update baseline * Revert baseline change due to stale output * Resolve all-object intersections inside spreads This means that getSpreadType will return an object type, even when spreading two intersections, as long as those intersections contain nothing but object types themselves. * Update and improve spread intersection tests * Simplify expression in resolveObjectIntersection * Update baselines with new index signature rules * Move n-ary spread handling into separate function. To be moved to callers in the next step. * Move multiple-spread handling out of getSpreadType * Clean up and reorder getSpreadType body * Respond to PR comments * Error for call/construct signatures in spread type 1. Simplify the error reporting code to handle all kinds of signatures. 2. Remove index signature handling code when creating a spread type since it's an error anyway. * Update baselines with new spread type index errors * Explain writeSpreadType a little better * Add more commentary to getSpreadType * Initial implementation of 'keyof T' type operator * Introduce PropertyNameType * Move most of resolveModuleNameForLsHost to lsHost * Simplify isImplicitGlob test * Initial implementation of 'T[K]' property access types * add a fallback logic for older versions of node that don't support 'homedir' (#11845) * add a fallback logic for older versions of node that don't support 'homedir' * try os.homedir first * For JavaScript files, we report semantic errors for using TypeScript-only constructs from within a JavaScript file as syntactic errors. * Don't require `resolvedTsFileName` and `resolvedJsFileName`, just `resolvedFileName` and `extension`. Also, change search order to do all TS searching before searching for JS. * Fix #10108 (Completion suggestion for object literal with getter) (#11808) * Fix #10108 (Completion suggestion for object literal with getter) * completions for setter * Move helper functions to core (fix build) * Support parametric property access expressions + some renaming * rewrite void-returning statements in constructors that capture result of super call (#11868) * rewrite void-returning statements in constructors that capture result of super call * linter * only emit /// types reference for a symbol in d.ts file if all declarations of a symbol come from type reference directives (#11872) * only emit /// types reference for a symbol in d.ts file if all declarations of a symbol come from type reference directives * pass proper value for current directory when compiling .d.ts files * Fix bug: Return a resolution diagnostic for a `.jsx` import if `--allowJs` is turned off * Remove a comment about a parameter that no longer exists * Fix bug: We want to test for existence of the enum value, not whether it's non-zero * Fix: test for presence, not absence * Allow untyped imports * Simplify for loops in fourslash.ts * Rename to zipWith * Change diagnostic message * Make `extension` property of `ResolvedModule` optional; introduce `ResolvedModuleFull` interface for when the extension is provided. * Consider index signatures in type produced by 'keyof T' * Respond to PR comments * Refactor getIndexedAccessType to be reusable from checkIndexedAccess * Skip overloads with too-short function parameters If the parameter of an overload is a function and the argument is also a function, skip the overload if the parameter has fewer arguments than the argument does. That overload cannot possibly apply, and should not participate in, for example, contextual typing. Example: ```ts interface I { (a: number): void; (b: string, c): void; } declare function f(i: I): void; f((x, y) => {}); ``` This code now skips the first overload instead of considering. This was a longstanding bug but was only uncovered now that more functions expressions are context sensitive. * Test skip overloads w/too-short function params 1. Update changed baseline. 2. Add a new test with baseline. * Minor style improvements * Ignore optionality when skipping overloads * Revert "Merge pull request #11354 from Microsoft/map4" This reverts commit adfdae0, reversing changes made to aad663c. * Rename Experimental transform to ESNext 1. Spread/rest are no longer experimental. 2. We need a place to put stage 3 ES features. * Changes from CR feedback * disable CoS for inferred projects (#11909) * Updating test due to CR changes. The order of the diagnostic messages has changed due to concatenation changes * Do not use contextual signatures with too few parameters * isAritySmaller runs later: getNonGenericSignature * Rename TransformFlags.Experimental -> ESNext * enable non-ts extensions in inferred projects by default * update CFG to properly handle do statements * do not inline async IIFEs in control flow graph * Minor fixes * cache type for empty type literal (#11934) cache type for empty type literal * Improved error messages for invalid assignments to identifiers * Accept new baselines * Improved error messages for invalid assignments to properties * Accept new baselines * Improve more error messages * Accept new baselines * Fix realPathMap in test harness: Must be used in `directoryExists` * Add helper function * Update generated files (#11963) * Move eitherIsNotLiteral check into switch and === checks This improves error messages * Forbid augmentation of untyped module (#11962) * Forbid augmentation of untyped module * Just use `undefined` for untyped modules * Unify checking of indexed access expressions and indexed access types * Accept new baselines * Accept additional baselines * Make `cachingInServerLSHost` tests work with `runtests-browser` * Get literal type only once * Update baselines * Add missed test update * Improve unification by moving more logic to getIndexedAccessType * Add test cases to report errors for decorators in js file * Report all the js file errors and skip only the nodes that are not allowed in js Fixes #11800 * Fix 'keyof any' to produce 'string | number' * Fix #11396: Make error message referene `Promise` explicitly (#11982) * Simplify the checking for async function return type * Fix #11396: Make error message referene `Promise` explicitly * Minor fixes * Adding tests * Test case for property used in destructuring variable declaration * Mark property referenced in the destructuring as referenced Fixes #11324 * Spread types handle nested index [access] types Nested index [access] types are treated as assignable to themselves only, just like type parameters. * Test index [access] types inside spread types * module resolution: prefer locally defined ambient modules, reuse resolutions to ambient modules from the old program (#11999) module resolution: prefer locally defined ambient modules, reuse resolutions to ambient modules from the old program * Parse, bind and check rest elements * Downlevel emit of rest elements * Add rest tests * Update baselines * Remove spread types, leaving spread syntax/emit Spreads are still typed, but cannot be created from a non-object type. Tests still need to be updated. * Fix lint * Lock tslint version to 4.0.0-dev.0, because 4.0.0-dev.1 complains about unnecessary semicolons following properties * Remove spread type tests from spread tests * Spread handles index signatures from singleton spreads I broke it when simplifying the logic earlier. * Correct assignability for keyof types and type parameters * Update tests * Accept new baselines * Update objectRestAssignment test and baselines * Fix linting errors * Update objectRestAssignment test Missed previously, just got the baselines * Improve readability of ES next destructuring emit * Ensure transformFlags are correct before visiting a node. * Port #12027, #11980 and #11932 to master (#12037) * add test for the fix for overwrite emitting error * cr feedback * Address PR comments 1. Remove extra line in __rest shim. 2. Improve __rest vs __assign check for destructuring assignment. * Move convertForOf to factory for esnext and es2015 Saves a lot of duplicated code * Update improved baselines * Move transformFunctionBody to factory It is shared by es2015 and esNext transformers. This commit just adds a convertObjectRest flag to be passed on to flattenDestructuring functions, as well as adding necessary parameters to use the code outside a transformer. * Spread any types to any * add missing bind calls to properly set parent on token nodes (#12057) * Cache generic signature instantiations * Accept new baselines * Properly instantiate aliasTypeArguments * Add regression test * Revert incorrect logic from #11392 * Accept new baselines * Rename SpreadElementExpression -> SpreadAssignment and SpreadExpression (formerly SpreadElementExpression) -> SpreadElement * Add SpreadAssignment to visitors 1. visitNode 2. reduceNode 3. emit This fixes an emit bug for setters. * Add --target esnext Currently, this disables the rest and spread transforms. This will change as proposals enter and leave stage 3. * Add --target esnext tests and update baselines * Revert unneeded change and comments per PR * Rename variable in checkSwitchStatement per PR * Do not emit __rest for --target esnext * Add `realpath` implementation for lshost * Create spread property types eagerly This avoids the need for a synthetic symbol and later code called from getTypeOfSymbol. * Set spread type symbols in checkObjectLiteral Instead of getSpreadType. Also clean up special-case handling inside getSpreadType to be more readable. * Ports #12051 and #12032 into master (#12090) * use local registry to check if typings package exist (#12014) use local registry to check if typings package exist * enable sending telemetry events to tsserver client (#12035) enable sending telemetry events * Address more PR comments * return empty file watcher in case if target directory does not exist (#12091) * return empty file watcher in case if target directory does not exist * linter * property handle missing config files in external projects (#12094) * Reuse subtree transform flags for incrementally parsed nodes (#12088) * Port fix for #12069 (#12095) * reduce set of files being watched, increase polling interval (#12054) (#12092) * Update authors for release-2.1 * Include declaration file emit * use createHash from ServerHost instead of explicit require (#12043) * use createHash from ServerHost instead of explicit require * added missing method in ServerHost stub * (signature help) type parameter lists are never variadic (#12112) * Handle abstract and const modifiers * Downlevel array destructuring to ES6 in object rest Previously array destructuring inside an object destructuring with an object rest would downlevel the array destructuring to ES5. This breaks if the code that targets ES2015 is using iterators instead of arrays since iterators don't support [0] or .slice that the ES5 emit uses. * Improve nested destructuring test for ESNext emit Now with object destructuring inside array destructuring inside object destructuring! Each with their own array/object rest! Also updates baselines. * Add support for taking in jsxFactory option and report errors for invalid combinations * Treat `| undefined` like optionality in spread type * Add strictNullChecks test for object spread * Verify that jsxFactory is either identifier or qualified name * Resolve first identifier of the jsxFactory as part of type check * When emitting use jsx factory entity expression if provided * Transpile unit test case * Enabled test case for source map * Add test cases for when jsxFactory cannot be resolved * Parse the jsxFactory again in the checker instead of using cached value in the program * Adds error message for incompatible assignment of identically named type Fixes issue #12050 * Updated condition for more readability * Report errors for import helpers missing __rest * Correctly check spread assignments in strict mode Previously it crashed in the binder. * Test error for import helpers with no __rest * synthesize complete import declaration for tslib (#12151) * Add ES2017 string padding (#12152) * add es2017.string.d.ts for String.prototype.{padStart,padEnd} * append es2017.string.d.ts into es2017.d.ts * add es2017.string into commandLineParser * append es2017.string into error message for unit tests of commandLineParser * append es2017.string into Gulpfile * append es2017.string into Jakefile * Exclude js files in non-configured projects compile-on-save emitting (#12118) * Exclude js files in non-configured projects CoS emitting * remove unnecessary method * Merge release-2.1 into master (#12157) * Update LKG * Update version * Update LKG * Skip overloads with too-short function parameters If the parameter of an overload is a function and the argument is also a function, skip the overload if the parameter has fewer arguments than the argument does. That overload cannot possibly apply, and should not participate in, for example, contextual typing. Example: ```ts interface I { (a: number): void; (b: string, c): void; } declare function f(i: I): void; f((x, y) => {}); ``` This code now skips the first overload instead of considering. This was a longstanding bug but was only uncovered now that more functions expressions are context sensitive. * Test skip overloads w/too-short function params 1. Update changed baseline. 2. Add a new test with baseline. * Minor style improvements * Ignore optionality when skipping overloads * Do not use contextual signatures with too few parameters * isAritySmaller runs later: getNonGenericSignature * rewrite void-returning statements in constructors that capture result of super call (#11868) * rewrite void-returning statements in constructors that capture result of super call * linter * Update LKG * Fix emit inferred type which is a generic type-alias both fully and partially fill type parameters * Add tests and baselines * Skip trying to use alias if there is target type * Update baselines * Add diagnostics to remind adding tsconfig file for certain external project (#11932) * Add diagnostics for certain external project * Show tsconfig suggestion * fix lint error * Address pr * fix comment * Update error message * Flag for not overwrite js files by default without generating errors (#11980) * WIP * Properly naming things * refactor * apply the option to all files and check out options * Fix typo * Update LKG * lockLinter * use local registry to check if typings package exist (#12014) (#12032) use local registry to check if typings package exist * Add test for #11980 (#12027) * add test for the fix for overwrite emitting error * cr feedback * enable sending telemetry events to tsserver client (#12034) (#12051) enable sending telemetry events * Update LKG * Reuse subtree transform flags for incrementally parsed nodes (#12088) * Update LKG * Update version * Update LKG * Do not emit "use strict" when targeting es6 or higher or module kind is es2015 and the file is external module * Add tests and baselines * [Release 2.1] fix11754 global augmentation (#12133) * Exclude global augmentation from module resolution logic * Address PR: check using string literal instead of NodeFlags.globalAugmentation * Remove comment
@sheetalkamat: Is this the same issue as the following:
I hit this in 2.1.1 so I'm not sure if it's a different case. |
@grovesNL I do not see error being reported when I used TypeScript@next |
I'm seeing what I believe is this issue in the following class constructor: static $inject = ['$window', '$location'];
private productCode: string;
private sourceCode: string;
private productData: any;
constructor(private $window: ng.IWindowService,
private $location: ng.ILocationService) {
this.productCode = $location.search().apptype;
this.sourceCode = $location.search().sourcecode_1;
this.productData = this.getProductData();
} It is happening for $location if I use it to set properties directly in the constructor but if I create a function to do it then call that in the constructor it's fine eg: static $inject = ['$window', '$location'];
private productCode: string;
private sourceCode: string;
private productData: any;
constructor(private $window: ng.IWindowService,
private $location: ng.ILocationService) {
this.setProductCodes();
this.productData = this.getProductData();
}
private setProductCodes() {
this.productCode = this.$location.search().apptype;
this.sourceCode = this.$location.search().sourcecode_1;
} I'm moving forward with the second set of code as it's better practice anyway but thought this may help people who find this issue on Google. |
Hi @loliver, in the first example you don't seem to ever access |
TypeScript Version: 2.1.0-dev.20161003
Code
Expected behavior:
If I have the
noUnusedLocals
option enabled, the code should compile without warnings because thespecies
property is being used.Actual behavior:
If I have the
noUnusedLocals
option enabled, I receive:The text was updated successfully, but these errors were encountered: