-
-
Notifications
You must be signed in to change notification settings - Fork 195
Open
Labels
enhancementNew feature or requestNew feature or requestquestionFurther information is requestedFurther information is requested
Description
Hello,
I use typia and noticed that it would be great to have able to compare A and B
How it could be:
import typia from 'typia'
type User = {
name: string
age: number
address: {
room?: number
city: string
street: string
}
}
const ivan: User = {
name: 'ivan',
age: 19,
address: {
street: 'Ivanovskaya',
city: 'Berlin'
}
}
let cache: User | null = null
function heavyFunction(user: User) {
if (t.compare<User>(user, cache)) {
return 'cached'
}
// heavy operation
cache = user
return 'non-cached'
}
heavyFunction(ivan) // -> 'non-cached'
heavyFunction(ivan) // -> 'cached'Compare unwraps in:
if (
user === cache || (
user.name === cache.name &&
user.age === cache.age &&
(user.address === cache.address ||
(user.address.room === cache.address.room && user.address.city === cache.address.city && user.address.street === cache.address.street)
)
)) {
return 'cached'
}Copilot
Metadata
Metadata
Labels
enhancementNew feature or requestNew feature or requestquestionFurther information is requestedFurther information is requested