You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks, I haven't noticed that it enabled it for .json files as well. Shouldn't it be named test.json.d.ts instead of test.d.ts though? Since json files can be imported only with extension, generated declarations would always reference it as ./test.json, which wouldn't find test.d.ts. Another solution there would be to trim .json extension for declaration resolution, like .js, but there is an another problem it causes - it's not allowed to have .ts and .json files with the same name anymore.
LOAD_AS_FILE(X)
1. If X is a file, load X as JavaScript text. STOP
2. If X.js is a file, load X.js as JavaScript text. STOP
3. If X.json is a file, parse X.json to a JavaScript Object. STOP
4. If X.node is a file, load X.node as binary addon. STOP
Yah, our filename generation assumes the same extension stripping behavior on import for all extensions. I'm... Conflicted? On generating a obj.json.d.ts instead of obj.d.ts. I don't want to special case it. In theory, it shouldn't be treated any differently than .ts or .tsx or any other supported extension; but our implementation of json file imports doesn't seem to have the same resolution behaviors that normal imports do (which is odd, since .json is lIke any other supported extension in node). Thing is, any non-technical reason one has to justify generating a obj.json.d.ts also justifies generating file.ts.d.ts and the like (as you're equally capable of having .ts and .js and .tsx and .jsx files of the same name side-by-side)... And I really don't think we wanted to start doing that. Because of that, I'm inclined to want to introduce extension stripping declaration file lookup for json imports, just like what other extensions do, instead... (Despite knowing that yes, it prevents you from having multiple files with the same name in the same place - I don't think it's been a problem for .tsx and .ts, so I'd hope people can work with .json the same way)
I'm in a Catch 22 situation here, and would really appreciate a way out - e.g., a boolean flag to turn off declaration output for json - e.g., declarationJson:
declaration: false for my projects that use JSON is not an option, because Composite projects may not disable declaration emit. Also, I want the types.
Renaming the JSON is not an option, because the framework (loopback@^3) requires the model and implementation files to have the same name.
Setting resolveJsonModule: false will require to re-introduce the Gulp hell I have now been able to get out of to move JSON files to the dist directory.
Wesley Wigham (@weswigham) - I understand there are many considerations to take into account here, but some way to deal with this issue would be nice.
Am I correct in thinking this also poses a problem in projects that don't specify an outDir? For some foo.json a foo.d.ts get's generated. Unlike .d.ts files generated from .ts files, this new foo.d.ts is included during compilation. Generating an error like this:
error TS5055: Cannot write file '/foo/bar/package/lib/foo.d.ts' because it would overwrite input file.
Activity
sheetalkamat commentedon Oct 28, 2019
#32372 enables declaration for
.js,.jsxand.jsonfilesark120202 commentedon Oct 30, 2019
Thanks, I haven't noticed that it enabled it for
.jsonfiles as well. Shouldn't it be namedtest.json.d.tsinstead oftest.d.tsthough? Since json files can be imported only with extension, generated declarations would always reference it as./test.json, which wouldn't findtest.d.ts. Another solution there would be to trim.jsonextension for declaration resolution, like.js, but there is an another problem it causes - it's not allowed to have.tsand.jsonfiles with the same name anymore.fatcerberus commentedon Oct 30, 2019
Hmm, Node at least will load
.jsoneven without an extension:https://nodejs.org/api/modules.html#modules_all_together
weswigham commentedon Oct 30, 2019
Yah, our filename generation assumes the same extension stripping behavior on import for all extensions. I'm... Conflicted? On generating a
obj.json.d.tsinstead ofobj.d.ts. I don't want to special case it. In theory, it shouldn't be treated any differently than.tsor.tsxor any other supported extension; but our implementation of json file imports doesn't seem to have the same resolution behaviors that normal imports do (which is odd, since.jsonis lIke any other supported extension innode). Thing is, any non-technical reason one has to justify generating aobj.json.d.tsalso justifies generatingfile.ts.d.tsand the like (as you're equally capable of having.tsand.jsand.tsxand.jsxfiles of the same name side-by-side)... And I really don't think we wanted to start doing that. Because of that, I'm inclined to want to introduce extension stripping declaration file lookup for json imports, just like what other extensions do, instead... (Despite knowing that yes, it prevents you from having multiple files with the same name in the same place - I don't think it's been a problem for.tsxand.ts, so I'd hope people can work with.jsonthe same way)fatcerberus commentedon Oct 30, 2019
Point against
file.ts.d.tsspecifically: TS actually errors on imports ending in.ts.raymondfeng commentedon Nov 5, 2019
Wesley Wigham (@weswigham) Maybe at least there should be a flag to disable emitting declaration files for
*.json?feat(cli): generate datasource json with '.config.json` extension
feat(cli): generate datasource json with '.config.json` extension
feat(cli): generate datasource json with '.config.json` extension
feat(cli): generate datasource json with '.config.json` extension
chore: rename datasource.json files to avoid conflicts with datasourc…
chore: rename datasource.json files to avoid conflicts with datasourc…
feat(cli): generate datasource json with '.config.json` extension
chore: rename datasource.json files to avoid conflicts with datasourc…
thovden commentedon Dec 20, 2019
I'm in a Catch 22 situation here, and would really appreciate a way out - e.g., a boolean flag to turn off declaration output for
json- e.g.,declarationJson:declaration: falsefor my projects that use JSON is not an option, becauseComposite projects may not disable declaration emit.Also, I want the types.loopback@^3) requires the model and implementation files to have the same name.resolveJsonModule: falsewill require to re-introduce the Gulp hell I have now been able to get out of to move JSON files to thedistdirectory.Wesley Wigham (@weswigham) - I understand there are many considerations to take into account here, but some way to deal with this issue would be nice.
wschella commentedon Jan 18, 2020
Am I correct in thinking this also poses a problem in projects that don't specify an
outDir? For somefoo.jsonafoo.d.tsget's generated. Unlike.d.tsfiles generated from.tsfiles, this newfoo.d.tsis included during compilation. Generating an error like this:weswigham commentedon Jan 18, 2020
It's the same thing the happens when you have both a
foo.tsand afoo.tsxorfoo.jsin the same place in a build, yes.weswigham commentedon Apr 7, 2020
AFAIK this was already done in #36066, so I'm closing this.
chore: rename datasource.json files to avoid conflicts with datasourc…
chore: rename datasource.json files to avoid conflicts with datasourc…