typescript-is
typescript-is copied to clipboard
Generated code duplication
import { is } from 'typescript-is';
interface IUser {
name: string;
}
let user1: IUser = { name: 'Hello' },
user2: IUser = {} as IUser;
if (is<IUser>(user1) && is<IUser>(user2)) {
console.log(user1.name, user2.name)
}
In this example there are 2 uses of is
with the same interface IUser
.
Current implementation inlines all usages of is
, so it cause a code duplication.
Is it possible to generate some kind of cache/registry
where all definitions will be stored?`
Hi @wheercool
At the moment this is not possible, except using for example the createIs
function:
import { createIs } from 'typescript-is';
interface IUser {
name: string;
}
const isUser = createIs<IUser>(); // Generate code for IUser once.
if (isUser(user1) && isUser(user2)) {
...
}
At the moment there is no "smart" caching or sharing of code between types that does this automatically.