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 does not work with defaults #16354

Closed
jantimon opened this issue Jun 8, 2017 · 3 comments
Closed

Typescript does not work with defaults #16354

jantimon opened this issue Jun 8, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@jantimon
Copy link

jantimon commented Jun 8, 2017

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
Try it yourself using this Playground Link

Code

    function fancyMethod({ option1 = true }: { option1?: boolean } = {}) {
        console.log(option1);
    }
    
    fancyMethod("abc");
    fancyMethod(false);
    fancyMethod(42);

Expected behavior:

Typescript will let me know that "abc" or false or 42 are not of type { option1?: boolean }.

Actual behavior:

No type error is shown

@ikatyang
Copy link
Contributor

ikatyang commented Jun 8, 2017

Possible duplicate of #7485, and it was said that was fixed by #16047.

See #16247 (comment)

But it seems primitive types are still not considered a weak type.

EDIT: should fixed in #16343

@jantimon
Copy link
Author

jantimon commented Jun 8, 2017

Thanks for your feedback :)

Is there any way to find out the current playground version number?
Is there a nightly playground?

@ikatyang
Copy link
Contributor

ikatyang commented Jun 8, 2017

You can see the version in the console.
image

But I think it will be v2.3.3+ based on #16131 (comment), so weird.

And selectable playground version is tracked by #15662.

EDIT: fix typo

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jun 8, 2017
@mhegazy mhegazy closed this as completed Jun 8, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants