Skip to content

Commit 72249a6

Browse files
committed
[twisty] Remove warning for setting TwistyPlayer alg using string.
This will depend on microsoft/TypeScript#42425 landing in stable TypeScript so we can update the types to reflect it.
1 parent 185a941 commit 72249a6

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/cubing/twisty/dom/TwistyPlayer.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Alg } from "../../alg";
22
import { TwistyPlayer } from "./TwistyPlayer";
3+
import "../../alg/test/alg-comparison";
34

45
describe("TwistyPlayer", () => {
56
it("can be constructed", () => {
@@ -8,4 +9,14 @@ describe("TwistyPlayer", () => {
89
});
910
expect(twistyPlayer.alg.experimentalNumUnits()).toEqual(3);
1011
});
12+
13+
it("can set alg using string", () => {
14+
const twistyPlayer = new TwistyPlayer({
15+
alg: new Alg("R U R'"),
16+
});
17+
// TODO(https://github.com/microsoft/TypeScript/pull/42425): remove `@ts-ignore`.
18+
// @ts-ignore
19+
twistyPlayer.alg = "F2";
20+
expect(twistyPlayer.alg).toBeIdentical(new Alg("F2"));
21+
});
1122
});

src/cubing/twisty/dom/TwistyPlayer.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,11 @@ export class TwistyPlayer extends ManagedCustomElement {
127127
this.#legacyExperimentalPG3DViewConfig = legacyExperimentalPG3DViewConfig;
128128
}
129129

130-
set alg(newAlg: Alg) {
130+
// TODO(https://github.com/microsoft/TypeScript/pull/42425): Allow setting string in the type decl.
131+
set alg(newAlg: Alg /* | string*/) {
131132
// TODO: do validation for other algs as well.
132133
if (typeof newAlg === "string") {
133-
console.warn(
134-
"`alg` for a `TwistyPlayer` was set using a string. It should be set using a `Sequence`!",
135-
);
136-
newAlg = new Alg((newAlg as unknown) as string);
134+
newAlg = Alg.fromString(newAlg);
137135
}
138136
this.#config.attributes["alg"].setValue(newAlg);
139137
this.cursor?.setAlg(newAlg, this.indexerConstructor()); // TODO: can we ensure the cursor already exists?

0 commit comments

Comments
 (0)