phetsims / circuit-construction-kit-common

"Circuit Construction Kit: Basics" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
10 stars 10 forks source link

@ts-expect-error in circuit-construction-kit-dc-main.ts #909

Closed pixelzoom closed 1 year ago

pixelzoom commented 1 year ago

This line in circuit-construction-kit-dc-main.ts:

if ( !window.circuitConstructionKitTestSuite ) {

... was causing CT errors and blocking other devs, so I added a @ts-expect-error to unblock.

The TS error was:

TS2339: Property 'circuitConstructionKitTestSuite' does not exist on type 'Window & typeof globalThis'

Oddly, the same line was not a problem in the other CCK main.ts files.

pixelzoom commented 1 year ago

A couple other things:

pixelzoom commented 1 year ago

The other 2 mains are JavaScript files. And in those files, WebStorm flags window.circuitConstructionKitTestSuite as “Unresolved variable circuitConstructionKitTestSuite”. So I'm guessing your best options for resolving this in TypeScript is something like:

- // @ts-expect-error
- if ( !window.circuitConstructionKitTestSuite ) {
+ type WindowKey = keyof typeof window;
+ if ( !window[ 'circuitConstructionKitTestSuite' as WindowKey ] ) {
samreid commented 1 year ago

Fixed, closing.