Skip to content

Instantly share code, notes, and snippets.

@yaeda
Last active May 17, 2017 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaeda/3881d93bf57cac69f4258661fee98ad5 to your computer and use it in GitHub Desktop.
Save yaeda/3881d93bf57cac69f4258661fee98ad5 to your computer and use it in GitHub Desktop.
Why I want to introduce namespace
class SomeDevice {
constructor(private peripheral: Noble.Peripheral) {
}
public connect(): void {
this.peripheral.connect();
}
public disconnect(): void {
this.peripheral.disconnect();
}
}
import { Peripheral } from "@types/noble";
class SomeDevice {
constructor(private peripheral: Peripheral) {
}
public connect(): void {
this.peripheral.connect();
}
public disconnect(): void {
this.peripheral.disconnect();
}
}
import * as noble from "noble";
class SomeDevice {
constructor(private peripheral: noble.Peripheral) {
}
public connect(): void {
this.peripheral.connect();
}
public disconnect(): void {
this.peripheral.disconnect();
}
}
@yaeda
Copy link
Author

yaeda commented May 17, 2017

These are simple implementation of Peripheral wrapper class.
Currently only case2 and case3 work.
After introducing namespace, all of case1, case2 and case3 work.

case1
After introducing namespace, we can write like this.
Any imports are not needed because tsc automatically load @types/noble.

case2
Currently this kind of import statement is needed despite tsc automatically load @types/noble.

case3
We can also write like this, but noble implementation is not needed in this class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment