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

Binding patterns should imply non-nullability #9429

Closed
yuit opened this issue Jun 29, 2016 · 2 comments
Closed

Binding patterns should imply non-nullability #9429

yuit opened this issue Jun 29, 2016 · 2 comments
Labels
Bug A bug in TypeScript Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it

Comments

@yuit
Copy link
Contributor

yuit commented Jun 29, 2016

TypeScript Version: master-build
As originally suggested by @shovon in comment in additional of passing undefined/null in destructing parameter as suggested by the comment, destructing, in general, should never be allow undefined or null
Code

// All should be error
var {} = undefined;
var {} = null;
var [] = undefined;
var [] = null;

function one ({}) {}
function two([]) {}
function three({foo: string, bar: number}) {}
function four([a, b]: number[]) {}
function five({} = undefined) {}
function six([] = undefined) {}
one(undefined);
one(null)
two(undefined);
two(null);
three(undefined);
three(null);
four(undefined):
four(null);
five(undefined);
five(null);
six(undefined);
six(null);

// This is ok
function foo({} = {}) {}
function bar([] = []) {}
foo(undefined);
foo(null);
bar(undefined);
bar(null);
@yuit yuit added the Bug A bug in TypeScript label Jun 29, 2016
@DanielRosenwasser DanielRosenwasser changed the title Destructing should be non-nullability Binding patterns should imply non-nullability Jun 30, 2016
@shovon
Copy link

shovon commented Jul 12, 2016

@DanielRosenwasser @yuit is this not slated for TypeScript 2.0?

@mhegazy
Copy link
Contributor

mhegazy commented Jul 13, 2016

All the function calls are already handled with --strictNullChecks. outside --strictNullChecks mode, null and undefined are valid input for these functions, do not see why we should disallow that. this is analogs to var x: {} = undefined, which is allowed.

The first set of var declarations are not flagged. but the empty destructing patters are are esoteric at best. var {a} = undefined is again flagged under --strictNullChecks.

I do not think we should add the concept of nullablity if --strictNullChecks is not set.

@mhegazy mhegazy closed this as completed Jul 13, 2016
@mhegazy mhegazy added the Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it label Jul 13, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Projects
None yet
Development

No branches or pull requests

3 participants