Giter VIP home page Giter VIP logo

Comments (9)

tylerbutler avatar tylerbutler commented on July 19, 2024 1

We have had a lot of discussion about this over the past year, and some things were implemented, like AsJsonable. However, the general consensus has been that this requires too much "fancy type handling" and ultimately is more confusing than helpful.

The current plan is to close this, and possibly remove the things we put in place already with follow up issues.

from fluidframework.

DLehenbauer avatar DLehenbauer commented on July 19, 2024

Typescript complains abt. the circular reference if I attempt to support nested arrays like this (e.g., [[[ . ]]]):

export type JsonArray = (JsonPrimitive | JsonObject | JsonArray)[];

(Perhaps @skylerjokiel, @anthony-murphy or @jack-williams have a trick.)

from fluidframework.

anthony-murphy avatar anthony-murphy commented on July 19, 2024

it can be worked around with more interfaces, but recursive types are coming in typescript 3.7:
https://httptoolkit.tech/blog/5-big-features-of-typescript-3.7/

from fluidframework.

jack-williams avatar jack-williams commented on July 19, 2024

Yeah until microsoft/TypeScript#33050 lands it has to be done with an interface:

export interface JsonArray extends Array<JsonPrimitive | JsonObject | JsonArray> {}

from fluidframework.

DLehenbauer avatar DLehenbauer commented on July 19, 2024

Note: Json introduced in #165

from fluidframework.

DLehenbauer avatar DLehenbauer commented on July 19, 2024

The Jsonable definition works well for anonymous objects, but requires casting through 'unknown' in both directions when casting to/from a compatible interface. :-/

    interface ICell {
        text: JsonablePrimitive;
        cache: JsonablePrimitive;
    }

    private loadCell(row: number, col: number): ICell {
        return this.matrix.getItem(row, col) as unknown as ICell;
    }

    private storeCell(row: number, col: number, cell: ICell) {
        return this.matrix.setItems(row, col, [cell as unknown as Jsonable]);
    }

from fluidframework.

jack-williams avatar jack-williams commented on July 19, 2024

Yeah this is abit of a pain. You can always do:

type ICell = {
    text: JsonablePrimitive;
    cache: JsonablePrimitive;
}

or

interface ICell {
    text: JsonablePrimitive;
    cache: JsonablePrimitive;
    [other: string]: unknown
}

The latter is probably more honest unless you're explicitly filtering out properties before serialising.

Could also do:

private loadCell(row: number, col: number): ICell {
    return this.matrix.getItem(row, col) as Pick<ICell, keyof ICell>;
}

private storeCell(row: number, col: number, cell: Pick<ICell, keyof ICell>) {
    return this.matrix.setItems(row, col, [cell as Jsonable]);
}

from fluidframework.

okjodom avatar okjodom commented on July 19, 2024

tagging myself for future developments on this issue

from fluidframework.

 avatar commented on July 19, 2024

Because this issue is marked as "won't fix" and has not had activity for over 3 days, we're automatically closing it for house-keeping purposes.

from fluidframework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.