Open vabatta opened 2 months ago
Tested, but not working due to no actual property of T
type exists.
class TypeGuardError<T = any> extends Error {
public readonly method!: string;
public readonly path!: string | undefined;
public readonly expected!: string;
public readonly value!: any;
}
let s: TypeGuardError<string> = null!;
let n: TypeGuardError<number> = null!;
// NO PROBLEM
s = n;
n = s;
To make it work, I have to make a fake property like below.
But cannot sure this is the right way.
class TypeGuardError<T = any> extends Error {
public readonly method!: string;
public readonly path!: string | undefined;
public readonly expected!: string;
public readonly value!: any;
protected readonly fake_expected_value_?: T;
}
let s: TypeGuardError<string> = null!;
let n: TypeGuardError<number> = null!;
// COMPILE ERROR
s = n;
n = s;
Description
When a
typia.assert<T>()
throws theTypeGuardError
, would be nice to have the originalT
name interface as part of theError
object thrown so that it can be used to connect which interface has thrown.Example
From the doc:
Would throw
Or with a change in the API