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

Allow component fields to be declared const (Think PropTypes in React) #880

Closed
maxamante opened this issue Oct 2, 2017 · 4 comments
Closed
Labels
awaiting submitter needs a reproduction, or clarification

Comments

@maxamante
Copy link

Recently, I've implemented a component that has a field that needs to be declared const. Ideally, this field would be set on create and all changes to it would be thrown away. @TehShrike expressed in Gitter the desire for functionality like PropTypes/duck-type checking. At the suggestion, I thought of 'PropAttrs', that would allow a user to declare the field's desired properties and Svelte would perform checks on create/update. Thoughts?

@Rich-Harris
Copy link
Member

I wonder if this is another argument for supporting TypeScript/Flow annotations? (See #418.) We could do this sort of thing:

<script language='typescript'>
  interface Data {
    readonly foo: string;
  };

  export default <Options>{
    data() {
      return <Data>{
        foo: 'x'
      };
    }
  };
</script>

Anyway, for posterity's sake, here's the workaround mentioned in Gitter — using helpers: https://svelte.technology/repl?version=1.40.1&gist=93912bc8b9ad55b97492e33d3d9d833b

@arxpoetica
Copy link
Member

@maxamante how are things going for you on this issue?

@arxpoetica arxpoetica added proposal awaiting submitter needs a reproduction, or clarification and removed question labels Jan 8, 2018
@maxamante
Copy link
Author

Hello. @arxpoetica Rich's workaround helped me figure out a solution. You can close if you need to.

@arxpoetica
Copy link
Member

Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification
Projects
None yet
Development

No branches or pull requests

3 participants