Scripting: layer instanceof TileLayer produces a type error
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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