microsoft / microsoft/pxt-microbit

Cast to class or interface

Open
#1,916 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Error Message P2
Dominant language
TypeScript
Stars
804
Forks
721
Avg merge
2d 9h
Merged PRs (30d)
2

Description

Describe the bug
In PXT 4.4, cast to class or interface is not supported.
image
In PXT 5.5, no error is displayed on the JavaScript editor but the code does not run.
image
image

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://makecode.microbit.org/beta
  2. Switch to JavaScript
  3. Paste the code below to the editor
interface Length {
    length: number;
}
function showLength(x: Length) {
    basic.showNumber(x.length);
}
showLength([]);
showLength("X");
  1. See error

Expected behavior
Either the cast is disallowed with error or it works successfully.

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

Start at the JavaScript editor in the PXT micro:bit beta and reproduce the issue with the provided Length interface, showLength function, and calls using [] and "X". Trace whether the invalid cast is diagnosed or reaches runtime; done means the code is consistently rejected with an error or executes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
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.