This can be tested in the playground :
Work as expected :
import { reflect } from 'typescript-rtti';
interface Shape {
foo: number
bar: string
}
export class A {
takeShape(shape? : Shape): Shape {
return null;
}
}
const shape = reflect<Shape>().as('interface').reflectedInterface;
console.log(shape.getProperty('foo')?.type ?? '<NOT FOUND>')
console.log(shape.getProperty('bar')?.type ?? '<NOT FOUND>')
Output :
class Number
class String
Doesn't work as expected :
import { reflect } from 'typescript-rtti';
interface Shape {
foo: number
}
interface Shape {
bar: string
}
export class A {
takeShape(shape? : Shape): Shape {
return null;
}
}
const shape = reflect<Shape>().as('interface').reflectedInterface;
console.log(shape.getProperty('foo')?.type ?? '<NOT FOUND>')
console.log(shape.getProperty('bar')?.type ?? '<NOT FOUND>')
Output :
The emitted JS show us that the underlying type variable is generated twice :
var IΦShape = { name: "Shape", prototype: {}, identity: Symbol("Shape (interface)") };
This can be tested in the playground :
Work as expected :
Output :
Doesn't work as expected :
Output :
The emitted JS show us that the underlying type variable is generated twice :