4

Recently I had the following situation in VSCode in a typescript project:

file: some-interface.ts

// no import statements have been skipped. This is the whole file:
export interface SomeInterface {
    property: AnotherInterface;         
}

and file: another-interface.ts:

export interface AnotherInterface {
    // ...
}

Okay - as there is no import statement in the some-interface.ts VS code showed me the error that the type AnotherInterface could not be found. Of course this is expected behavior. But as soon I accidently removed the export keyword from another-interface.ts - VS code stopped complaining and could correctly resolve the type.

So do anyone know what's going on here? Is this expected behavior or rather a bug of either typescript or vs code?

Dale K
  • 16,372
  • 12
  • 37
  • 62
jlang
  • 743
  • 8
  • 24

1 Answers1

5

So do anyone know what's going on here? Is this expected behavior or rather a bug of either typescript or vs code?

This is the expected behavior. If there is no export neither import in a file, then it is a script instead of a module. Then, in a script, all members are global.

See also: Classic scripts v/s module scripts in Javascript

Paleo
  • 16,013
  • 3
  • 44
  • 62