Skip to content
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

auto generate ts file? #97

Closed
wants to merge 22 commits into from
Closed

auto generate ts file? #97

wants to merge 22 commits into from

Conversation

greggman
Copy link
Owner

This is not a real PR. It's just to allow you to take a look. See #89

this uses the tsd-jsdoc npm package
https://www.npmjs.com/package/tsd-jsdoc

it gets a few errors and no idea how close the types
are. Maybe someone more familar with typescript can take a look?

checked in the generated types here

You can run it with

npm install
./node_modules/.bin/grunt jsdoc:ts

greggman and others added 6 commits January 13, 2019 02:42
this uses the tsd-jsdoc npm package
https://www.npmjs.com/package/tsd-jsdoc

it gets a few errors and no idea how close the types
are. Maybe someone more familar with typescript can take a look?

checked in the generated types here

You can run it with

    npm install
    ./node_modules/.bin/grunt jsdoc:ts
/** comment */ was being confused as a docstring and resulting in TS declaration pollution
use

    npm run buildts

to re-run the ts generator and apply the script
Fixes this typo in docs and in the "mungets" task:
WebGLContextCreationAttirbutes => WebGLContextCreationAttributes
All fields are optional but lacked the [default brackets] that would let grunt know about this when outputting the TypeScript definitions
These functions were documented as accepting a "subdivisionsThick" argument after "subdivisionsDown" but before "startOffset", though the function does not in fact accept such an argument.

Error was revealed by WIP TypeScript test.
"npm run test" will now run both the pre-existing "js" tests as well as the new "ts" test. Use "npm run testjs" to run only the earlier tests.

Borrows a handful of lines from code in the examples/ directory. It doesn't need to do anything interesting, it just needs to successfully compile.

The TS test is not very thorough at this point, but it's a very solid start imo.
pineapplemachine and others added 8 commits January 14, 2019 14:12
This is also probably the source of the build failure in commit 0e66391
Remove "types.d.ts"
Add "twgl-full.d.ts" and "twgl.d.ts"
Previously in the global scope (e.g. twgl.Vec3) and now in module scope (e.g. twgl.v3.Vec3)
because I can
@pineapplemachine
Copy link
Contributor

Re #50 (comment): I looked at the examples and didn't actually understand what the purpose of them actually was or how they were meant to run. I'd suggest removing the TypeScript-related examples for the time being if you are having trouble with them, and maybe adding functioning TS-specific examples later on.

@greggman
Copy link
Owner Author

greggman commented Jan 14, 2019 via email

@pineapplemachine
Copy link
Contributor

pineapplemachine commented Jan 14, 2019

Zero proof, do you mean the definitions?

If so, that's what npm run testts is for. It runs the TypeScript compiler tsc on a source file at test/src/ts/test.ts using the configuration at test/src/ts/tsconfig.json. If tsc runs without errors, then there cannot be any major issues with the definitions. Any uncaught minor issues are very probably due to documentation errors like the ones you fixed in 43cd3d3

The only way to verify through tests that no more such errors exist is to write TypeScript code utilizing every type and function in twgl. Which is an honorable goal, but a terrible prerequisite for just getting out something that works and can be maintained, since there doesn't seem to be anything like this out there yet.

It is not actually important to run any JavaScript to verify that the definitions are correct. TypeScript does not change language behavior from JavaScript; it only turns certain errors that would normally be runtime errors into compile-time errors - i.e. they happen when you run tsc and not while you're testing it in a browser. If you are encountering errors in the browser when trying to run the output of TypeScript compilation (like if you compiled and tried to run the examples) then there is an error with the implementation - either the example source or the library JS code - not with the definitions.

@pineapplemachine
Copy link
Contributor

pineapplemachine commented Jan 14, 2019

Think of TypeScript as a complicated linter. The *.d.ts files are the linter config, and test/src/ts/test.ts is a reference source file which you know follows all the rules you want to enforce.

Your reference file should go through the linter without any errors. If there are any errors, then your linter config isn't right. If there are no errors, then the linter config matches up to what you expected. Executing code that is validated by the linter does not actually say anything about the correctness of the linter config.

Same deal with TypeScript. Executing the output of tsc does not actually say anything about the correctness of the definitions. If npm run testts runs without errors - meaning tsc ran without errors - then that means the *.d.ts definitions succeeded in describing test/src/ts/test.ts as valid TypeScript source.

@greggman greggman closed this Jan 16, 2019
@greggman greggman deleted the gen-ts branch July 4, 2020 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants