Skip to content

Interfaces are not merged #121

@ppoulard

Description

@ppoulard

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 :

<NOT FOUND>
class String

The emitted JS show us that the underlying type variable is generated twice :

var IΦShape = { name: "Shape", prototype: {}, identity: Symbol("Shape (interface)") };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions