Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface properties generates incompatible TypeScript interfaces #3830

Closed
leononame opened this issue May 28, 2024 · 1 comment
Closed

Interface properties generates incompatible TypeScript interfaces #3830

leononame opened this issue May 28, 2024 · 1 comment

Comments

@leononame
Copy link

Description

I've stumbled across this when implementing an indexed property through an interface. When adding properties to F# interfaces that have getters that require a value, the generated TypeScript interfaces have a different type signature than the classes implementing those

Repro code

See in the REPL: https://fable.io/repl/#?code=C4TwDgpgBAkgShAhgEwPIDsA2IbuRAD0QCNMIAeAcgGsIQAaKSgN0UwFdoB3ACwnSa0QALigQAjuzYBLUAD4oAXgBQUNVBIBnYACdEAY2CxgEALaiadKAFoFLNpyhdZPKAHMIwZctCQoAEXZTUxw8QhIyKiFGew5uPgFLETFJGXklVXVpdBMdADMDaHgkNCxQ-CJSCiSY1jiFZ2AeTPV1UzNiCB0oJulNADoYE1MW1rHG1w8jISUoAulMCagAIkRNZDzl718ihBQAdR1ZCFwKiOropjrHXn5BOlEJKUxZEAUVVq1dAyMhswsZrYrg5uC53J5GJpPNtwNBAsFyuEqnB9lE6LUQU4Evdkk80m8Mq1srkCvpdiVDsdTkjIjVgfUnC5Rq12qZOt1egM-iMxrzGU1wdMrIo5ogFktVutNsy+Yg8FAoUKQFBrtARQAKACUyiAA&html=Q&css=Q

Or see this code snippet:

type IReadOnlyIndexable<'key, 'value when 'key: equality> =
    abstract Item: 'key -> 'value with get

type DummyIndexable<'key, 'value when 'key: equality> =
    interface IReadOnlyIndexable<'key, 'value> with
        member this.Item
            with get key = failwith "asdf"

type IReadWriteIndexable<'key, 'value when 'key: equality> =
    abstract Item: 'key -> 'value with get, set

type DummyIndexableRW<'key, 'value when 'key: equality> =
    interface IReadWriteIndexable<'key, 'value> with
        member this.Item
            with get key = failwith "asdf"
            and set key value = ()

Expected and actual results

The generated TypeScript code looks like this:

import { class_type, TypeInfo } from "fable-library-js/Reflection.js";

export interface IReadOnlyIndexable$2<key, value> {
    Item(arg0: key): value
}

export class DummyIndexable$2<key, value> implements IReadOnlyIndexable$2<key, value> {
    constructor() {
    }
    get_Item(key: key): value {
        throw new Error("asdf");
    }
}

export function DummyIndexable$2_$reflection(gen0: TypeInfo, gen1: TypeInfo): TypeInfo {
    return class_type("Test.DummyIndexable`2", [gen0, gen1], DummyIndexable$2);
}

export interface IReadWriteIndexable$2<key, value> {
    Item(arg0: key): value,
    Item(arg0: key, arg1: value): void
}

export class DummyIndexableRW$2<key, value> implements IReadWriteIndexable$2<key, value> {
    constructor() {
    }
    get_Item(key: key): value {
        throw new Error("asdf");
    }
    set_Item(key: key, value: value): void {
    }
}

export function DummyIndexableRW$2_$reflection(gen0: TypeInfo, gen1: TypeInfo): TypeInfo {
    return class_type("Test.DummyIndexableRW`2", [gen0, gen1], DummyIndexableRW$2);
}

However, the interface has the property as Item, whereas the implementing classes have get_Item and set_Item.

@ncave
Copy link
Collaborator

ncave commented May 29, 2024

Fixed by #3831

@ncave ncave closed this as completed May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants