-
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
Completion list for JSON files imported using CommonJS require #9221
Completion list for JSON files imported using CommonJS require #9221
Conversation
Hi @vojtechhabarta, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! The agreement was validated by Microsoft and real humans are currently evaluating your PR. TTYL, MSBOT; |
//cc @DanielRosenwasser who was looking into this earlier. |
+1 |
@vojtechhabarta sorry for the delay. I am a bit busy with TS 2.0 release at the moment, but i would love to get this change in once that is out. |
It would be nice if this could be generalized. If the user writes an import statement like import * as json1 from './json1'; or import json1 from './json1'; // iff "allowSyntheticDefaultImports": true it should work just as well. @mhegazy what do you think? |
I wanted to resubmit this PR based on current master but I don't know how to solve one thing. Recently #11370 was merged which adds following change: "Return type of require call is from external module resolution only if it doesn't resolve to local module" (checker.ts:12797 - https://github.com/Microsoft/TypeScript/pull/11370/files). // @allowjs: true
// @outDir: dist
// @Filename: m1.js
export var a = 42;
// @Filename: m2.js
const m1 = require("./m1");
const a = m1.a;
// @Filename: node.d.ts
interface NodeRequireFunction {
(id: string): any;
}
interface NodeRequire extends NodeRequireFunction {
}
declare var require: NodeRequire; type of Same applies for @mhegazy, @sheetalkamat do you have any idea how this could be improved so it works also with node.d.ts? |
Checkout this #11819 |
16ce1c1
to
ac8edc6
Compare
Thanks @sheetalkamat for the link, that's exactly what I needed. @mhegazy I rebased this PR on current master branch. |
closing in favor of #13665 |
Fixes #7071
This change provides completion lists for JSON files that are loaded using CommonJS
require
function.For example for
json1.json
fileand
test.ts
fileTypeScript compiler now provides completion list with
foo
andbar
items.Implementation
It is implemented as proposed in #7071 (comment) comment.
parseObjectLiteralExpression()
function.json
extensionScriptKind.JSON
EDIT: removed description of my problem with tests (solved by updating dependencies using
npm install
)