Skip to content

type-only import prevents declaration of a value with the same name #40583

Closed
@1000hz

Description

@1000hz

TypeScript Version: 4.1.0-dev.20200915

Search Terms: ts1361 type-only import type 'Foo' cannot be used as a value because it was imported using 'import type'.

Code

import type { Foo } from "./Foo";

function Foo(): Foo {
  return {
    name: "index.ts"
  };
}

Foo(); // 'Foo' cannot be used as a value because it was imported using 'import type'.ts(1361)

Expected behavior: Since the import type only creates a symbol in the type realm, I expect to be able to create the same symbol in the value realm without conflict. Especially since it's possible to declare the same symbol as both a type and value from within a single file.

Actual behavior: An error is raised: 'Foo' cannot be used as a value because it was imported using 'import type'.ts(1361), which makes this behavior seem very much intended, though that seems to violate the feature's stated intent. From the description of the feature's Type semantics from #35200:

If the symbol does have a value side, name resolution for that symbol will see only the type side.

Playground Link: https://codesandbox.io/s/wizardly-chatelet-h8zkg?file=/src/index.ts

Related Issues: #35200

cc: @andrewbranch

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions