Last active
May 17, 2017 03:23
-
-
Save yaeda/3881d93bf57cac69f4258661fee98ad5 to your computer and use it in GitHub Desktop.
Why I want to introduce namespace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeDevice { | |
constructor(private peripheral: Noble.Peripheral) { | |
} | |
public connect(): void { | |
this.peripheral.connect(); | |
} | |
public disconnect(): void { | |
this.peripheral.disconnect(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Peripheral } from "@types/noble"; | |
class SomeDevice { | |
constructor(private peripheral: Peripheral) { | |
} | |
public connect(): void { | |
this.peripheral.connect(); | |
} | |
public disconnect(): void { | |
this.peripheral.disconnect(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as noble from "noble"; | |
class SomeDevice { | |
constructor(private peripheral: noble.Peripheral) { | |
} | |
public connect(): void { | |
this.peripheral.connect(); | |
} | |
public disconnect(): void { | |
this.peripheral.disconnect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.