-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
branch: typescript #360
Comments
I wrote a draft of Property, but there are some caveats.
|
New idea about how to temporarily use generic Property in typescript sims without having to turn on the typescript build chain for all sims: generate d.ts files from the axon/typescript branch and check the d.ts files in to master. Pros:
Cons:
This may be a good strategy until we enable typescript for all repos, if developers are OK with the tradeoffs in the cons section. |
While I was working on phetsims/bending-light#401, I noticed there is a JSDoc annotation for template variables in JavaScript, described here: https://stackoverflow.com/questions/16017627/document-generic-type-parameters-in-jsdoc When I applied this new JSDoc to Property, TypeScript was able to read and understand it. So that seems like a preferable solution until we approve TypeScript in common code. I tested JavaScript usages in Fourier and they didn't seem disturbed. I'll commit this to master shortly. |
I was able to use the same JSDoc template pattern for Emitter, supporting an array of types. It's working really well. const e0 = new Emitter<[]>();
e0.emit(); // ok
e0.emit( 'testing' ); // bad
e0.addListener( () => {} ); // ok
e0.addListener( ( age: number ) => {} ); // bad
const e1 = new Emitter<[ boolean ]>();
e1.emit( true ); // ok
e1.emit( 'hello' ); // bad
e1.addListener( ( enabled: boolean ) => {} ); // ok
e1.addListener( ( age: number ) => {} ); // bad
const e2 = new Emitter<[ string, number ]>();
e2.emit( 'bye', 7 ); // ok
e2.emit( 'null' ) // bad
e2.addListener( ( name: string, age: number ) => {} ); // ok
e2.addListener( ( name: string, age: number, time: Date ) => {} ); //bad |
Branch deleted, closing. |
From phetsims/chipper#1069
The text was updated successfully, but these errors were encountered: