mapeditor / mapeditor/tiled

Scripting: layer instanceof TileLayer produces a type error

Open
#3,232 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

qt issue
Dominant language
C++
Stars
12.9k
Forks
2k
Avg merge
4h 27m
Merged PRs (30d)
8

Description

Hey :)

Thanks for making Tiled ❤️

When implementing an exporter to a custom level format from Tiled's `TileMap`, I managed to produce a type error (`TypeError: Type error`) from the script when doing:

```js
const isTileLayer = layer instanceof TileLayer; // For the record, layer really was a TileLayer
```

In the `d.ts`, `TileLayer` is defined as:

```js
declare class TileLayer extends Layer
```

.. but I imagine this is probably not a JS class, but Tiled's data structure that is just accessible from JS, but it likely doesn't implement all the operators.

I know, there's `Layer.isTileLayer`, but this probably shouldn't crash.

Also, I checked other layer types (`GroupLayer`, `ImageLayer` and `ObjectGroup`), and they behave the same. Not sure about other API types.

Platform: Windows
Tiled Version: 1.7.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the TypeError from `layer instanceof TileLayer` in the Tiled scripting API, using the `TileLayer`, `GroupLayer`, `ImageLayer`, and `ObjectGroup` cases described. Start by comparing the `d.ts` declarations with the runtime scripting behavior and `Layer.isTileLayer`; done means these layer checks no longer raise a type error while preserving the documented type checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.