I study generics. In the code:
class Dictionary<TKey, TValue> { private _data: KeyValuePair<TKey, TValue>[] = []; add(key: TKey, value: TValue): void { const entry = new KeyValuePair<TKey, TValue>(); entry.key = key; entry.value = value; this._data.push(entry); } get(key: TKey): TValue | null { return this._data.find(el => el.key === key); // <-- } } tsconfig.json:
{ "compilerOptions": { "module": "commonjs", "target": "es5", "sourceMap": true, "lib": ["esnext", "es5", "es6", "es7", "es2015", "es2016", "es2017", "es2018"] }, ... } Error: (70, 23) TS2339: Property 'find' does not exist on type 'KeyValuePair []'.
Why is this error, because I declared that the array?
libproperty intsconfig'e? - overthesanity