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

[TypeScript] boolean optional prop is typed as foo?: boolean #636

Closed
jacekkarczmarczyk opened this issue Jan 23, 2021 · 4 comments
Closed
Labels
bug Something isn't working typing

Comments

@jacekkarczmarczyk
Copy link
Contributor

jacekkarczmarczyk commented Jan 23, 2021

Following code

// main.ts
import Vue from 'vue';
import { defineComponent } from '@vue/composition-api';

let bool = false;

Vue.extend({
  props: { foo: Boolean },
  mounted () {
    bool = this.foo; // No error
  },
});

defineComponent({
  props: { foo: Boolean },
  setup (props) {
    bool = props.foo; // <!--- Error
  },
});

throws a TS error:

  Type 'undefined' is not assignable to type 'boolean'.
    18 |   props: { foo: Boolean },
    19 |   setup (props) {
  > 20 |     bool = props.foo;
       |     ^
    21 |   },
    22 | });
@danielroe
Copy link
Member

This looks like the correct behaviour to me.

@pikax pikax added bug Something isn't working typing labels Jan 23, 2021
@jacekkarczmarczyk
Copy link
Contributor Author

This looks like the correct behaviour to me.

Doesn't look for me, if prop is not passed its value is bool: https://codepen.io/jkarczm/pen/VwKOEzp

@pikax
Copy link
Member

pikax commented Jan 23, 2021

Is not the correct behaviour, if Boolean is passed, it will be implicit converted to false if not provided

@jacekkarczmarczyk
Copy link
Contributor Author

that can be closed i guess?

@antfu antfu closed this as completed May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typing
Projects
None yet
Development

No branches or pull requests

4 participants