Похожие чаты

Is it possible to inform TS not to expand firstname

and lastname when building the template literals of same object?

export interface Person {
first_name: string,
last_name: string,
name: `${Person['first_name']} ${Person['last_name']}`
}
as above name prop type will be string.

or that is only possible by constructing the type from a literal expression (with const assertion)?

3 ответов

33 просмотра

export interface Person<FirstName extends string, LastName extends string> {

function person <F extends string, L extends string>(first: F, last: L, name: `${F} ${L}`) { return { first, last, name }; } person( "Muthu", "Kumar", "" // Argument of type '""' is not assignable to parameter of type '"Muthu Kumar"'.(2345) )

Похожие вопросы

Обсуждают сегодня

Карта сайта