-
Notifications
You must be signed in to change notification settings - Fork 46
Conversation
@@ -8,7 +8,7 @@ | |||
"license": "MIT", | |||
"scripts": { | |||
"build": "rimraf dist && tsc && copyfiles -u 1 src/type-collector-snippet.ts dist", | |||
"format": "prettier --write src/**/*.ts packages/**/src/**.ts", | |||
"format": "prettier --write src/*.ts src/**/*.ts packages/**/src/**.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for adding src/*.ts
? afaik src/**/*.ts
also includes any .ts files directly under src
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least for me (on Arch Linux) it is required or the files directly under src
are ignored.
src/apply-types.ts
Outdated
@@ -81,29 +67,20 @@ export function applyTypesToFile( | |||
replacements.push(Replacement.insert(opts.parens[0], '(')); | |||
suffix = ')'; | |||
} | |||
if (opts && opts.comma) { | |||
suffix = ', '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure opts.comma
and opts.parens
are mutually exclusive? Otherwise, we need to account for the case where both opts.comma
and opts.parens
set suffix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opts.parens
is only used for one parameter arrow functions so this should never happen since arrow functions use the surrounding this
and therefore don't need an explicit this
type.
src/apply-types.ts
Outdated
replacements.push(Replacement.insert(pos, ': ' + prefix + sortedTypes.join('|') + suffix)); | ||
if (opts && opts.thisType) { | ||
replacements.push(Replacement.insert(pos, 'this')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we add two replacement at the same position, let's use the third priority
parameter for Replacement.insert
to guarantee that this
will always come before the colon. Or we can just combine both into one replacement - similar to what with do with prefix
and suffix
, we can add another variable called thisPrefix
or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a thisPrefix
variable in the latest commit.
src/integration.spec.ts
Outdated
`); | ||
}); | ||
|
||
it('should not add `this` type', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is should not add this this here? Let's change the test description to explain that (e.g. "it should not add this
type in case it can be inferred")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expanded the explanation.
class NestError extends Error {} | ||
|
||
export type ISourceLocation = [string, number]; /* filename, offset */ | ||
|
||
interface IKey { | ||
filename: string; | ||
pos: number; | ||
opts: any; | ||
opts: ICollectedTypeInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Though, I think it will make more sense to go the other way around - move the definition of ICollectedTypeInfo
here, and import it in apply-types
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the type to type-collector-snippet.ts
.
Lovely, thank you very much! I left a few comments, but overall looks really nice :) |
Thanks for the quick review, I addressed your comments in the latest commit. |
Awesome, thanks! Just out of curiosity - have you used TypeWiz on any of your projects? |
What is not yet covered by this PR (and was also not covered in #27) is how to roll out these changes to |
Just saw your comment, I have experimentally added typewiz to rtf.js where I use a custom script for instrumentation. |
Very interesting - so in this case, you are basically writing an instrumented copy of your source code to the I couldn't find where you told the bundle / test steps to read the source files from the |
It works as follows:
|
Got it, thanks! I'm currently helping migrate immer to TS using typewiz, and they are also using rollup for their build. In their case, I used rollup-plugin-typescript2. In your build, you are running TypeScript as a separate compile step. Is there any reason for preferring running TypeScript separately and not as part of rollup? |
In rtf.js we build three separate bundles (for rtf.js, emf.js and wmf.js) but building rtf.js requires building the other two with tsc in the same step (because of some import tricks it uses) so if it used the rollup plugin emf.js and wmf.js would be built twice. |
And how useful have you found TypeWiz so far for rtf.js? |
Sadly I found your blog post too late. A month ago it was just three plain ES5 files with around 9000 lines of code and then I did the entire conversion by hand and added all the typings :( |
I hear you... I did the same with several projects before coming up with TypeWiz. But the future will be brighter :) |
Released as part of 0.7.0 |
Optionally applies
this
types to functions. Fixes #33 .