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

properties of instances as generic type / type parameter #238

Open
Mlocik97 opened this issue Jan 31, 2023 · 3 comments
Open

properties of instances as generic type / type parameter #238

Mlocik97 opened this issue Jan 31, 2023 · 3 comments

Comments

@Mlocik97
Copy link

Mlocik97 commented Jan 31, 2023

let say for example I have instance of search.

const custom_search = search.create({
        type: search.Type.SALES_ORDER,
        filters: [...], // some filters here
        columns: ["cust_field1", "cust_field2"]
})

// custom_search.columns
// TSC tells it's type is `string[]`

is what I get rn. is string[].... that's meh.... I specified array, that is already populed with specific values.
it would be nice, if TSC would tell it's type is ["cust_field1", "cust_field2"].

This would be possible with something like (ofc it's not really working solution, we need to handle search.column and it's properties too):

create<T extends ( string | search.column )>({
      columns: T[]
}): {
      columns: T[]
}

LET'S DO IT!

@MrRob
Copy link
Collaborator

MrRob commented Feb 6, 2023

@Mlocik97 Sounds interesting! Do you want to create a pull request for this?

@ShawnTalbert
Copy link
Contributor

Can someone illustrate how this would be used?

It's very rare in my experience to manipulate that columns array after creating the search?

Or is the goal not to change the array but merely read it in a strongly typed way?

@Mlocik97
Copy link
Author

Mlocik97 commented Feb 6, 2023

I use it in my library... I don't need to write to columns, just read it in a strongly typed way.

I will see how a lot of time I will have, and will try to create PR.

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

No branches or pull requests

3 participants