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
Include Typescript types inside repository #2353
Comments
@SomaticIT — Great work, thanks for posting this. There's a related issue on tko: knockout/tko#6 — which is already transpiled with Typescript. @mbest Is there any intention of / ability to include Typescript definitions in ko 3.x? |
Thank you for your quick response! |
Thanks for sharing your work on this! I'd like to get this into Knockout as well. |
Hi @mbest, |
@SomaticIT Thanks. What's a Typescript migration project? :) |
As a big Typescript and KO user who long ago took the DefinitelyTyped definitions and updated them (probably around the time components landed) I'd be keen to see your PR and put in our own improvements & tweaks too. I'll keep watch :) |
I just submitted a PR with an improved version of typed-contrib types. |
I've made some updates to the code from @SomaticIT. See 70b7d7c. Please look over them and let me know if you find any problems. I'm still pretty new to TypeScript, so I may have missed something. |
I left some notes 👍 BTW: Has this already landed in latest beta (assuming the beta itself is not too unstable)? If so, I'd like to test these bindings on my real-life project. |
@Sebazzz No release yet. That should be coming soon. Thanks for your notes. I'll make some changes based on them. |
@mbest I found that It causes some issues in extensions libraries. |
Good catch. I'll get that fixed before release. |
How do you tell Typescript to use the definitions from the knockout npm package instead of types/knockout? (I have both installed because types/knockout-validation still depends on types/knockout ) |
I don't know. @SomaticIT? Anyone else? |
The knockout's Typescript should use embedded types in priority. As a workaround, you sould be able to exclude {
"exclude": [
"**/@types/knockout/**/*.d.ts"
]
} I think it should work. |
I believe according to this comment microsoft/TypeScript#11137 (comment) that TypeScript is going to go to @ Types first and the exclude isn't looked at for resolving global declarations... |
I discovered a problem with the type definitions I've set up and am wondering if any of you have a solution. If you look at https://github.com/knockout/knockout/blob/master/build/types/knockout.d.ts#L23, we have: subscribe(callback: SubscriptionCallback<Array<utils.ArrayChange<T>>>, callbackTarget: any, event: "arrayChange"): Subscription; The problem is that for arrays, |
I don't think so, people are saying the type info is only available at compile time. https://stackoverflow.com/questions/51906554/get-class-name-of-generic-parameter-passed-typescript They suggest to pass the constructor of the class as a paramter to the type, to help keep that information at runtime, but it feels awfully invasive. Edit: Instantiating a new instance of the provided type automatically, and get the value from the default constructor result. |
I asked my question on SO and got an answer pretty quickly: https://stackoverflow.com/a/53973228/1287183 Here's what I did: type Flatten<T> = T extends Array<infer U> ? U : T;
...
subscribe<TTarget = void>(callback: SubscriptionCallback<utils.ArrayChanges<Flatten<T>>, TTarget>, callbackTarget: TTarget, event: "arrayChange"): Subscription; https://blogs.msdn.microsoft.com/typescript/2018/03/15/announcing-typescript-2-8-rc/ |
Hi, But when it comes to the included definition, what are the thoughts on the knockout plugins that have typings in DefinitelyTyped? Is the preferred solution to write issues on them to include typings compatible with this one in their packages? |
I think the best solution is to update the Knockout definitions in DefinitelyTyped to match Knockout's own. Then the various plugins should be updated to match the new type names. |
My $0.02: the name changes are going to be a massive breaking change for
everyone using knockout and typescript.
I agree that there should be an official d.ts file but I think the naming
should more closely match the existing DefinitelyTyped naming to ease the
transition.
…On Sat, Mar 2, 2019 at 8:57 PM Michael Best ***@***.***> wrote:
I think the best solution is to update the Knockout definitions in
DefinitelyTyped to match Knockout's own. Then the various plugins should be
updated to match the new type names.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2353 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANX6X6WaArzW8UPNOC-GHR8Kqbm06Deks5vSywOgaJpZM4SMXbD>
.
|
I think type aliases might resolve this compatibility issue for now m
|
@mbest The workaround I took was to override the definition and run on definitelytyped for 3.4.2 to have the definitions for the plugins work for now. Could a better solution be for the plugins to start including definitions, compatible with 3.5? |
@SimmeNilsson Now that Hope it could help for you... |
@SomaticIT Oh, that would certainly help. Will you target definitelytyped or the packages themselves? |
Can anyone help me out? I just updated my package.json file (using npm-check-updates) to the latest versions of all my packages. This moved me to tyepscript 3.5.1. Knockout 3.5.0. And we rely heavily on knockout-mapping and knockout.validation. But we were using @types/knockout, @types/knockout.mapping and @types/knockout.validation. However my project no longer compiles. I have hundreds of custom validators and mapping references. So I now have hundreds of errors about 'mapping' and 'validation' not existing on 'ko'. |
@cosmoKenney If it is any help, it is not ideal, but I still use the definitelyTyped, even for knockout 3.5.0 itself. Granted I miss out on some newly added functions, but for now I decided the trade off was worth it. |
@SimmeNilsson thanks for the reply. I'm having trouble with the plugins: mapping and validation. I suppose I could include them in the paths option? And then |
@cosmoKenney I have paths for mapping as well. Because it mixes separating the name with dot and dash between the types package and the actual libraries. This is my setup: npm packages: tsconfig.json paths: imports (typescript) |
@SimmeNilsson thank you! |
@SomaticIT / @mbest can you provide some context on why you decided on
as opposed to
the latter is type correct since the original definitelytyped had the latter and although it's a pain to access an observable since it doesn't know when you've set a value |
@SomaticIT do you have type definitions for knockout.mapping and knockout.validation published somewhere? |
@ai-fwd You are right. The typing should include |
I worked on The The |
@SomaticIT First, thank you for providing the types for knockout.validation. but typescript is complaining that isValid() is not a property of an observable. I grabbed a copy of the knockout.validation typing file from the PR on that project that you created. And I have 3.5.0 of Knockout installed with it's types. Hmmm, I noticed that you imported * as ko in the typing file. Is that how you import ko in all of your code? I used to do that with pre-3.5.0 but with 3.5.0 I start to import just the classes / functions that I use. |
|
@SomaticIT I am finding that some of the validations aren't parsing properly. For instance:
this gives an error that it doesn't match any of the 3 overrides of extend with "number is not assignable to RegExp | ValidationRuleExtenderParams" I get the same thing for equal when I try to say a boolean needs to equal true. |
@SomaticIT I am looking into another issue where I am using min and max where the values I am comparing against are actually observables. This isn't parsing correctly with the typings. BTW, is there a better place for me to put these issues? and Equal isn't working when I use a fixed value. For instance, I have a boolean where I want valid to be true when the boolean is true and invalid when false. But I get an error when I use: .extend({ equal: true }) because true can't be converted to a Subscribable. |
Can you add a comment with a report of bugs you found in the I will make an update based on your feedback. Thanks |
Hi wonderful knockout team !
I wrote precise TypeScript types definitions for knockout.
Definitions can be found here: https://github.com/typed-contrib/knockout/blob/master/global/index.d.ts
This project was written for the
typings
which is shutting down leaving me with two solutions:DefinitelyTyped
types.I prefer the second solution because it avoids having multiple dependencies in NPM.
Indeed, TypeScript compiler automatically finds types which are included in NPM packages.
Do you agree to include these types?
If you do, I can open a PR to make the appropriate configuration for you.
Thank you very much for this library which I really make huge use!
You can find most of my knockout related open-source projects here
The text was updated successfully, but these errors were encountered: