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

[Bug] SimpleMeshLayer Typescript types are incorrect for "mesh" property #9136

Open
1 of 7 tasks
joshuarpearce opened this issue Sep 3, 2024 · 0 comments
Open
1 of 7 tasks
Labels

Comments

@joshuarpearce
Copy link

Description

I'm following the API Reference docs for SimpleMeshLayer - specifically [here]https://deck.gl/docs/api-reference/mesh-layers/simple-mesh-layer#mesh). I'm trying to pass an object as the docs suggest I should be able to however I get a typescript error that there is a type mismatch:

Type '{ positions: Float32Array; normals: Float32Array; texCoords: Float32Array; }' is not assignable to type '({ positions: Float32Array; normals: Float32Array; texCoords: Float32Array; } & (string | Mesh | Promise<Mesh> | null)) | undefined'.
  Type '{ positions: Float32Array; normals: Float32Array; texCoords: Float32Array; }' is not assignable to type '{ positions: Float32Array; normals: Float32Array; texCoords: Float32Array; } & Promise<Mesh>'.
    Type '{ positions: Float32Array; normals: Float32Array; texCoords: Float32Array; }' is missing the following properties from type 'Promise<Mesh>': then, catch, finally, [Symbol.toStringTag]ts(2322)

Flavors

  • Script tag
  • React
  • Python/Jupyter notebook
  • MapboxOverlay
  • GoogleMapsOverlay
  • CartoLayer
  • ArcGIS

Expected Behavior

If I create a SimpleMeshLayer and provide a correctly formatted object for the mesh property, I would expect no type errors and the typescript compiler to build it without any issues.

Steps to Reproduce

The data and layer I use are below, the issue I have is with typing the mesh property of the layer. As you can see from the description, it seems as though it expects the object to have the fields it does, but also be a promise.

export const getShape= () => {
    const positions = [
        // left side
        0, 0, 0,
        -0.4, 1, -0.2,
        -0.4, 1, 0.2,

        // right side
        0, 0, 0,
        0.4, 1, -0.2,
        0.4, 1, 0.2,

        // bottom
        0, 0, 0,
        -0.4, 1, -0.2,
        0.4, 1, -0.2,

        // top
        0, 0, 0,
        -0.4, 1, 0.2,
        0.4, 1, 0.2,
    ];
    const normals = positions.map((_, i) => i);
    const texCoords = positions.map((_, i) => i);

    const meshObj = {
        positions: new Float32Array(positions.length),
        normals: new Float32Array(normals.length),
        texCoords: new Float32Array(texCoords.length)
    };

    for (const pos in positions) {
        meshObj.positions.set([positions[pos]], +pos);
    }

    for (const nor in normals) {
        meshObj.normals.set([normals[nor]], +nor);
    }

    for (const tex in texCoords) {
        meshObj.texCoords.set([texCoords[tex]], +tex);
    }

    return meshObj;
};

const meshLayer = new SimpleMeshLayer({
        id: 'SimpleMeshLayer',
        data: [
            { coordinates: [0, 0, 10000] },
            { coordinates: [0, 1, 10000] },
            { coordinates: [1, 0, 10000] },
        ],
        opacity: 0.1,
        wireframe: true,
        getColor: () => [255, 0, 0],
        getOrientation: () => [0, 0, 0],
        getPosition: (d) => d.coordinates,
        mesh: getShape(),
        sizeScale: 30000,
        pickable: true,
    });

Environment

  • Framework version: 9.0.28
  • Browser: Firefox / Brave (N/A as issue as at build stage)
  • OS: Windows

Logs

Type '{ positions: Float32Array; normals: Float32Array; texCoords: Float32Array; }' is not assignable to type '({ positions: Float32Array; normals: Float32Array; texCoords: Float32Array; } & (string | Mesh | Promise<Mesh> | null)) | undefined'.
  Type '{ positions: Float32Array; normals: Float32Array; texCoords: Float32Array; }' is not assignable to type '{ positions: Float32Array; normals: Float32Array; texCoords: Float32Array; } & Promise<Mesh>'.
    Type '{ positions: Float32Array; normals: Float32Array; texCoords: Float32Array; }' is missing the following properties from type 'Promise<Mesh>': then, catch, finally, [Symbol.toStringTag]ts(2322)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant