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

bug: @Prop can't work with typescript's Type alias #3124

Closed
3 tasks done
zhuxindaba opened this issue Oct 28, 2021 · 8 comments
Closed
3 tasks done

bug: @Prop can't work with typescript's Type alias #3124

zhuxindaba opened this issue Oct 28, 2021 · 8 comments
Labels
Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through.

Comments

@zhuxindaba
Copy link

Prerequisites

Stencil Version

2.7.0

Current Behavior

image
image

Expected Behavior

can work correctly

Steps to Reproduce

none

Code Reproduction URL

none

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Oct 28, 2021
@rwaskiewicz
Copy link
Contributor

Hey @zhuxindaba 👋

Can you please add a reproduction to GitHub so that we may take a closer look? This greatly helps speed up the time it takes to diagnose and triage issues. Thanks!

@rwaskiewicz rwaskiewicz added Awaiting Reply This PR or Issue needs a reply from the original reporter. Repro: No and removed triage labels Oct 28, 2021
@zhuxindaba
Copy link
Author

Sorry, this is demo reproduction: https://github.com/zhuxindaba/stencil-demo/tree/master/demo-test

@ionitron-bot ionitron-bot bot added Reply Received and removed Awaiting Reply This PR or Issue needs a reply from the original reporter. labels Oct 28, 2021
@MarkChrisLevy
Copy link

MarkChrisLevy commented Oct 28, 2021

It is not about type alias, it is because you use type that is private (only accessible within one file). If you want to make it work just define ButtonTypes in separate file, e.g. export type ButtonTypes = .....

@zhuxindaba
Copy link
Author

It is not about type alias, it is because you use type that is private (only accessible within one file). If you want to make it work just define ButtonTypes in separate file, e.g. export type ButtonTypes = .....

Thx, I define the type in seperate file, it works. But, how can i use type alias privately?

@MarkChrisLevy
Copy link

MarkChrisLevy commented Oct 29, 2021

Types used within Prop or Method cannot be private, as they are accessed outside of the component.

@rwaskiewicz
Copy link
Contributor

Hey @zhuxindaba,

@MarkChrisLevy is correct here - it's difficult to declare a type that's used by a class member that's annotated with @Prop, because the type checker needs to know about it when you're passing props to it, at least in the context of a parent TSX component:

import { Component, h } from '@stencil/core';

@Component({
  tag: 'my-parent',
  shadow: true,
})
export class MyParent {
  render() {
    // if we don't make the type of `first` public with `export`, how do we know it is
    // that 'primary' is allowed?
    return <my-component first={"primary"}></my-component>;
  }
}

However, I think this could be improved on the Stencil end in 2 ways:

  1. This is not documented anywhere, and we should add it
  2. The developer experience for using a component in HTML (like in your example) should be improved.

I'm going to label this issue to get it added to our backlog + for the team to discuss this further

@rwaskiewicz rwaskiewicz added Repro: Yes Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through. and removed Repro: No labels Nov 1, 2021
@zhuxindaba
Copy link
Author

Hey @zhuxindaba,

@MarkChrisLevy is correct here - it's difficult to declare a type that's used by a class member that's annotated with @Prop, because the type checker needs to know about it when you're passing props to it, at least in the context of a parent TSX component:

import { Component, h } from '@stencil/core';

@Component({
  tag: 'my-parent',
  shadow: true,
})
export class MyParent {
  render() {
    // if we don't make the type of `first` public with `export`, how do we know it is
    // that 'primary' is allowed?
    return <my-component first={"primary"}></my-component>;
  }
}

However, I think this could be improved on the Stencil end in 2 ways:

  1. This is not documented anywhere, and we should add it
  2. The developer experience for using a component in HTML (like in your example) should be improved.

I'm going to label this issue to get it added to our backlog + for the team to discuss this further

thanks for your reply,i'm look forward stencil will solve the problem dynamically when compiling project.

@rwaskiewicz
Copy link
Contributor

ionic-team/stencil-site#784 has been created to address the documentation gap

@splitinfinities splitinfinities added Resolution: Needs Documentation Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through. and removed Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through. labels Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Refine This PR is marked for Jira refinement. We're not working on it - we're talking it through.
Projects
None yet
Development

No branches or pull requests

4 participants