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

More poor errors with value/type/namespace confusion #27630

Open
mattmccutchen opened this issue Oct 9, 2018 · 1 comment
Open

More poor errors with value/type/namespace confusion #27630

mattmccutchen opened this issue Oct 9, 2018 · 1 comment
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Help Wanted You can do this
Milestone

Comments

@mattmccutchen
Copy link
Contributor

"Cannot find name" or "Namespace ... has no exported member", but I see it right there! Some of the more common cases came up in two recent Stack Overflow questions: 1, 2. Maybe we should just fix all the cases?

TypeScript Version: master (f6ca105)

Search Terms: value type namespace meaning error (and all the error messages below)

Code

const v = 42;
type t = number;
namespace n {}
const vt = 42;
type vt = number;
const vn = 42;
namespace vn {}
type tn = number;
namespace tn {}

namespace M { 
    export const v = 42;
    export type t = number;
    export namespace n {}
    export const vt = 42;
    export type vt = number;
    export const vn = 42;
    export namespace vn {}
    export type tn = number;
    export namespace tn {}    
}

// Actual is OK: 't' only refers to a type, but is being used as a value here.
const v1 = t;
// Actual: Property 't' does not exist on type 'typeof M'.
// Proposed: 't' only refers to a type, but is being used as a value here.
const v2 = M.t;
// Actual is OK: Cannot use namespace 'n' as a value.
const v3 = n;
// Actual: Property 'n' does not exist on type 'typeof M'.
// Proposed: Cannot use namespace 'n' as a value.
const v4 = M.n;
// Actual: Cannot use namespace 'tn' as a value.
// Proposed: 'tn' only refers to a type and a namespace, but is being used as a value here.
const v5 = tn;
// Actual: Property 'tn' does not exist on type 'typeof M'.
// Proposed: 'tn' only refers to a type and a namespace, but is being used as a value here.
const v6 = M.tn;

// Actual: Cannot find name 'v'.
// Proposed: 'v' only refers to a value, but is being used as a type here.
type t1 = v;
// Actual: Namespace 'M' has no exported member 'v'.
// Proposed: 'v' only refers to a value, but is being used as a type here.
type t2 = M.v;
// Actual is OK: Cannot use namespace 'n' as a type.
type t3 = n;
// Actual: Namespace 'M' has no exported member 'n'.
// Proposed: Cannot use namespace 'n' as a type.
type t4 = M.n;
// Actual: Cannot use namespace 'vn' as a type.
// Proposed: 'vn' only refers to a value and a namespace, but is being used as a type here.
type t5 = vn;
// Actual: Namespace 'M' has no exported member 'vn'.
// Proposed: 'vn' only refers to a value and a namespace, but is being used as a type here.
type t6 = M.vn;

// Actual: Cannot find namespace 'v'.
// Proposed: 'v' only refers to a value, but is being used as a namespace here.
type nt1 = v.oops;
// Actual: Namespace 'M' has no exported member 'v'.
// Proposed: 'v' only refers to a value, but is being used as a namespace here.
type nt2 = M.v.oops;
// Actual is OK: 't' only refers to a type, but is being used as a namespace here.
type nt3 = t.oops;
// Actual: Namespace 'M' has no exported member 't'.
// Proposed: 't' only refers to a type, but is being used as a namespace here.
type nt4 = M.t.oops;
// Actual: 'vt' only refers to a type, but is being used as a namespace here.
// Proposed: 'vt' only refers to a value and a type, but is being used as a namespace here.
type nt5 = vt.oops;
// Actual: Namespace 'M' has no exported member 'vt'.
// Proposed: 'vt' only refers to a value and a type, but is being used as a namespace here.
type nt6 = M.vt.oops;

Expected behavior: As indicated above

Actual behavior: As indicated above

Playground Link: link

Related Issues: #7900

@ghost ghost added Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging labels Oct 9, 2018
@RyanCavanaugh RyanCavanaugh added this to the Community milestone Oct 9, 2018
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Oct 9, 2018
@tibi77
Copy link

tibi77 commented Oct 15, 2018

Can I work on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants