mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
The issue is with tsickle type inference and the bug should be assigned to them.
The offending code is:
```
function cacheMatchingDirectivesForNode(
tNode: TNode, tView: TView, localRefs: string[] | null): void {
const exportsMap = localRefs ? {'': -1} : null; // <<<<< ===== OFFENDING LINE
const matches = tView.currentMatches = findDirectiveMatches(tNode);
if (matches) {
for (let i = 0; i < matches.length; i += 2) {
const def = matches[i] as DirectiveDef<any>;
const valueIndex = i + 1;
resolveDirective(def, valueIndex, matches, tView);
saveNameToExportMap(matches[valueIndex] as number, def, exportsMap);
}
}
if (exportsMap) cacheMatchingLocalNames(tNode, localRefs, exportsMap);
}
```
because it generates invalid js closure code:
```
function cacheMatchingDirectivesForNode(tNode, tView, localRefs) {
const /** @type {(null|{: number})} */ exportsMap = localRefs ? { '': -1 } : null; // <<<<< ===== OFFENDING LINE
const /** @type {(null|!Array<?>)} */ matches = tView.currentMatches = findDirectiveMatches(tNode);
if (matches) {
for (let /** @type {number} */ i = 0; i < matches.length; i += 2) {
const /** @type {!tsickle_forward_declare_11.DirectiveDef<?>} */ def = /** @type {!tsickle_forward_declare_11.DirectiveDef<?>} */ (matches[i]);
const /** @type {number} */ valueIndex = i + 1;
resolveDirective(def, valueIndex, matches, tView);
saveNameToExportMap(/** @type {number} */ (matches[valueIndex]), def, exportsMap);
}
}
if (exportsMap)
cacheMatchingLocalNames(tNode, localRefs, exportsMap);
}
```
The workaround is to declare the type explicitly such as:
```
const exportsMap: ({[key:string]:number}|null) = localRefs ? {'': -1} : null;
```
which than generates valid closure code:
```
const /** @type {(null|!Object<string,number>)} */ exportsMap = localRefs ? { '': -1 } : null;
```
PR Close #23379
|
||
|---|---|---|
| .. | ||
| change_detection | ||
| debug | ||
| di | ||
| i18n | ||
| linker | ||
| metadata | ||
| profile | ||
| reflection | ||
| render | ||
| render3 | ||
| sanitization | ||
| testability | ||
| util | ||
| view | ||
| zone | ||
| application_init.ts | ||
| application_module.ts | ||
| application_ref.ts | ||
| application_tokens.ts | ||
| change_detection.ts | ||
| codegen_private_exports.ts | ||
| console.ts | ||
| core.externs.js | ||
| core.ts | ||
| core_private_export.ts | ||
| core_render3_private_export.ts | ||
| di.ts | ||
| error_handler.ts | ||
| errors.ts | ||
| event_emitter.ts | ||
| linker.ts | ||
| metadata.ts | ||
| platform_core_providers.ts | ||
| render.ts | ||
| type.ts | ||
| util.ts | ||
| version.ts | ||
| zone.ts | ||