-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
module declaration and conditional require #15902
Comments
Try doing it without import * as nobleA from "noble";
import * as nobleB from "noble-uwp";
const noble = /win/.test(process.platform) ? nobleB : nobleA; |
@andy-ms but the issue is that the import of "noble-uwp" wont work on macos as it is a windows module. That's why i am looking at declaring the module and using it as a "type" |
@farfromrefug You can use imports for the type and then use the types-only, not the value (e.g. https://github.com/TypeStrong/ts-node/blob/b751a56e8a094d6905e47e4c96ab43a931bf4cb8/src/index.ts#L180). You might want to prefix import * as noble from 'noble'
const x: typeof noble = require('noble') |
Full support for dynamic imports will come with |
@blakeembrey i tried what you suggest by doing this: declare module 'noble' {
export type State = "unknown" | "resetting" | "unsupported" | "unauthorized" | "poweredOff" | "poweredOn";
export var state: State
export interface Peripheral {
type: string
}
export interface Characteristic {
subscribe(callback?: (error: string) => void): void;
}
}
import * as _noble from 'noble';
let noble: typeof _noble = require('noble');
if (/win/.test(process.platform)) {
noble = require('noble-uwp');
} If i do interface Peripheral extends noble.Peripheral {
} i get an error @mhegazy thanks for the heads up. This will take quite some time i guesss? |
It is targeted for 2.4 at the moment, which isn't forever in the future. Next major release. |
@farfromrefug You can use |
@andy-ms i can't use |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Yesterday i was doing this which was working great:
Now i need to transform
import * as noble from 'noble'
into:Both require actually use the same declaration. However i can't find a way to tell typescript that
noble
is of 'type'noble
(the module)Is there any way to do this with typescript?
THanks
The text was updated successfully, but these errors were encountered: