Skip to content
Permalink
Browse files

fix(language-service): fix error of array-index out of bounds excepti…

…on (#33928)

PR Close #33928
  • Loading branch information
ivanwonder authored and mhevery committed Nov 27, 2019
1 parent 7faa9bb commit b05ce8539107a686d97f4d538e1c82a6687bd0e8
@@ -295,7 +295,8 @@ class TypeWrapper implements Symbol {
if (nType) {
// get the right tuple type by value, like 'var t: [number, string];'
if (nType.isUnion()) {
return new TypeWrapper(nType.types[value], this.context);
// return undefined if array index out of bound.
return nType.types[value] && new TypeWrapper(nType.types[value], this.context);
}
return new TypeWrapper(nType, this.context);
}
@@ -167,6 +167,13 @@ describe('diagnostics', () => {
.toBe(`Identifier 'badProperty' is not defined. 'Hero' does not contain such a member`);
});

it('should not produce errors if tuple array index out of bound', () => {
mockHost.override(TEST_TEMPLATE, `
{{tupleArray[2].badProperty}}`);
const diags = ngLS.getDiagnostics(TEST_TEMPLATE);
expect(diags).toEqual([]);
});

it('should not produce errors on function.bind()', () => {
mockHost.override(TEST_TEMPLATE, `
<test-comp (test)="myClick.bind(this)">

0 comments on commit b05ce85

Please sign in to comment.
You can’t perform that action at this time.