-
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
Support export { x as default }
in namespace declarations
#24164
Comments
So the request is to enable someting like: function gitRoot(cwd?: string): string {
return null;
}
namespace gitRoot {
export function isGitRoot(target: string) {
}
export { gitRoot as gitRoot };
export { gitRoot as default };
export const __esModule = true;
}
export = gitRoot; |
export { x as default }
in namespace declarations
my another try yargs2.ts import yargs = require('yargs');
import Argv from './core';
export * from './core'; // got overwrite at runtime, but make import didn't have error
Argv(process.argv.slice(2), undefined, {
supportPassArgs: true,
});
// @ts-ignore
export = Argv; runtime source of yargs2.js "use strict";
/**
* Created by user on 2018/6/1/001.
*/
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
const core_1 = require("./core");
__export(require("./core"));
core_1.default(process.argv.slice(2), undefined, {
supportPassArgs: true,
});
module.exports = core_1.default; demo.ts //import yargs = require('..'); // work
import * as yargs from '..' // work too
import { argv } from 'yargs2' // <=== ts don't know what can import , but without error
console.log(yargs.processArgs);
console.log(yargs.argv); // <=== ts know what `yargs.argv` is
console.log(argv); // <=== ts know what `argv` is |
looks like this a little near index.ts import { Trie } from './src/trie'
// @ts-ignore
import { AhoCorasick } from './src/ahocorasick'
// @ts-ignore
export { AhoCorasick, Trie }
// @ts-ignore
export default AhoCorasick
// @ts-ignore
export = AhoCorasick
exports = Object.assign(AhoCorasick, exports); index.d.ts import { Trie } from './src/trie';
import { AhoCorasick } from './src/ahocorasick';
export { AhoCorasick, Trie };
export default AhoCorasick;
export = AhoCorasick; index.js const trie_1 = require("./src/trie");
// @ts-ignore
const ahocorasick_1 = require("./src/ahocorasick");
// @ts-ignore
exports.default = ahocorasick_1.AhoCorasick;
exports = Object.assign(ahocorasick_1.AhoCorasick, exports);
module.exports = ahocorasick_1.AhoCorasick; temp.ts import * as AhoCorasick from '..';
import AhoCorasick2 from '..';
import AhoCorasick3 = require('..');
let a1 = new AhoCorasick;
let a2 = new AhoCorasick2;
let a3 = new AhoCorasick3;
let a11 = new AhoCorasick();
let a22 = new AhoCorasick2();
let a33 = new AhoCorasick3();
console.log(a1);
console.log(a2);
console.log(a3);
console.log(a11);
console.log(a22);
console.log(a33); |
still hope can have this |
declare function sortObject<T>(object: T, options?: sortObject.IOptions & {
useSource: true;
}): T;
declare namespace sortObject {
var default: typeof sortObject;
}
|
1 will compile nothing in .js , but we can hack it for work 4 is work both of .js and .d.ts, but still hope one of 1~3 is can work, because 4 only work for 11.1when
1.2when
=> .js (function (_CallClassWithoutNewDecorator) {
})(_CallClassWithoutNewDecorator || (_CallClassWithoutNewDecorator = {})); .d.tsin 1.1 or 1.2 export { callClassWithoutNewDecorator as default }; 2this is error too, but can output type
=> .d.ts const _default: typeof callClassWithoutNewDecorator;
export default _default; .js (function (_CallClassWithoutNewDecorator) {
export default = callClassWithoutNewDecorator;
})(_CallClassWithoutNewDecorator || (_CallClassWithoutNewDecorator = {})); 3
=> .d.ts export default callClassWithoutNewDecorator; .js (function (_CallClassWithoutNewDecorator) {
export default callClassWithoutNewDecorator;
})(_CallClassWithoutNewDecorator || (_CallClassWithoutNewDecorator = {})); 4
.ts callClassWithoutNewDecorator.default = callClassWithoutNewDecorator; => .d.ts declare namespace callClassWithoutNewDecorator {
var default: typeof callClassWithoutNewDecorator;
} .js callClassWithoutNewDecorator.default = callClassWithoutNewDecorator; |
still need can use because by some reason (performance), for ide typeof xxx, and function xxx is not same thing |
Search Terms
Suggestion
options for allow use import { xxx } from 'yyy'; when TS2497 resolves to a non-module entity
without warn or use
// @ts-ignore
Use Cases
Examples
demo.ts
git-root2
Checklist
My suggestion meets these guidelines:
[x] This wouldn't be a breaking change in existing TypeScript / JavaScript code
[x] This wouldn't change the runtime behavior of existing JavaScript code
[ ] This could be implemented without emitting different JS based on the types of the expressions
[ ] This isn't a runtime feature (e.g. new expression-level syntax)
The text was updated successfully, but these errors were encountered: