state.books.filter((book: { id: string }) => book.id !== id)
А лучше: interface Book {
id: string;
// ...
}
state.books.filter((book: Book) => book.id !== id)
А ещё лучше: interface Book {
id: string;
// ...
}
interface State {
books: Book[];
// ...
}
const state: State = ...
state.books.filter(book => book.id !== id)
class Main {
constructor(public name: string) {}
}
class Sub extends Main {
constructor(name: string, public lastname: string) {
super(name)
}
}
const sub = new Sub('michael', 'jackson')
function hello (person: Main) {
console.log(person.name)
if(person instanceof Sub) {
console.log(person.lastname)
}
}
hello(sub)
interface Dictionary<T> {
[key: string]: T
}
function serialize<T extends Dictionary<string | number[]>> (arg: T) {
var res = '';
var replaceNamePop: Dictionary<string> = {
modules: 'module',
categories: 'category',
searchFieldsList: 'searchFieldList'
};
Object.keys(arg).forEach(function (this: T, key) {
if (Array.isArray(this[key])) {
for (var j = 0; j < this[key].length; j++) {
if (typeof replaceNamePop[key] != 'undefined')
res += '&' + replaceNamePop[key] + '=' + this[key][j];
else
res += '&' + key + '=' + this[key][j];
}
} else {
if (typeof replaceNamePop[key] != 'undefined')
res += '&' + replaceNamePop[key] + '=' + this[key];
else
res += '&' + key + '=' + this[key];
}
}, arg);
return res;
}
serialize({
'modules': [20],
'categories': [20],
'keyword': 'keyword',
'time': 'time',
'catRelation': 'cat',
'sortField': 'sort',
'sortDirection': 'ASC',
'searchFieldsList': 'list'
});
serialize({
'modules': [20, 25],
'categories': [20, 58],
'keyword': 'keyword',
'time': 'time',
'catRelation': 'cat',
'sortField': 'sort',
'sortDirection': 'ASC',
'searchFieldsList': 'list'
});
serialize({
'modules': [20, 25],
'keyword': 'keyword'
});
declare module '*.scss' {
const scss: any;
export default scss
}
, чтоб он знал какие там где типы.class FormBuilder {
public static strategies: { [key: string]: {new(): IFormStrategy} } = {
simple: SimpleFormStrategy,
extended: ExtendedFormStrategy,
};
public build(params: { strategy: string }): Form {
let strategy: IFormStrategy = new FormBuilder.strategies[params.strategy]();
return strategy.execute(params);
}
}
FormBuilder.strategies.custom = CustomFormStrategy;
const formBuilder = new FormBuilder();
formBuilder.build({ strategy: 'custosm' });
this
для стрелочной функции, потому что ts сам его прекрасно видит - там тупо не может быть никаких вариантов и разночтений: this для стрелочной функции задаётся прямо на месте её создания и принимать никаких иных значений не может.this
используется не в стрелочной функции, а в типе свойства. interface TestInterface {
a: number;
b: string;
c: () => void;
}
и interface TestInterface {
c: () => void;
a: number;
b: string;
}
а в функции, очевидно, имеет. function test(a: TestInterface['a'], b: TestInterface['b'], c: TestInterface['c']): void {
// ,,,
}