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

Rewrite in TypeScript #28

Open
Widdershin opened this issue Nov 22, 2016 · 8 comments
Open

Rewrite in TypeScript #28

Widdershin opened this issue Nov 22, 2016 · 8 comments

Comments

@Widdershin
Copy link
Member

No description provided.

@atomrc
Copy link

atomrc commented Jul 26, 2017

Hi guys, I am in the process of adding types to @cycle/collection.

We'll see if I am really able to achieve this task but, for the moment, it's pretty smooth.

I have a question though, concerning default parameters' value.
Here is an example : https://github.com/cyclejs/collection/blob/master/src/collection.js#L30

The function collection takes an optional items parameter that defaults to an empty array. I'd like to type this parameters as an array of components but when I do I get errors from the typescript compiler.

  Type 'Component[]' is not assignable to type 'never[]'.   
    Type 'Component' is not assignable to type 'never'.   

I have a few ideas in mind, but I am not sure what is the best way to deal with this.

either

function collection(options: Options, items?: Array<Collection>) {
  items = items || []
}
  • any other way I do not know.

I am pretty new to typescript so the exercise is really interesting! If you have any tips to help my, I'd be grateful :)

@Hypnosphi
Copy link
Collaborator

Does it work if you use .never<Component>()?

@atomrc
Copy link

atomrc commented Jul 26, 2017

@Hypnosphi Where should I put this? in the signature?

@Hypnosphi
Copy link
Collaborator

Hypnosphi commented Jul 26, 2017

Oh, I though it's because of xs.never() used somewhere

@atomrc
Copy link

atomrc commented Jul 26, 2017

In general, I don't know how to deal with default values. Typescript won't let me type them. I'd like to do something like

function collection (options: Options, items = []: Array<Component>) {
}

But it seems typescript doesn't understand this notation

@Hypnosphi
Copy link
Collaborator

items: Array<Component> = [] maybe?

@atomrc
Copy link

atomrc commented Jul 26, 2017

@Hypnosphi oh god, it works!!! I am confused I though I tried this notation :/
Thanks and sorry for the noise

@shfrmn
Copy link

shfrmn commented Aug 1, 2018

Hi guys,

I just created a similar library called cycle-lot. It's 100% percent in typescript and uses proxies to make API simpler. I'd really appreciate your feedback on it.

Let me know what you all think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants