microsoft / microsoft/TypeScript
Document how to use tsconfig-related APIs in the wiki
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
"createProgram" "compiler" "compiler api" "js files createProgram" "js compiler api" "js files compiler" "programmatic compiler js"
🕗 Version & Regression Information
Give my project:
my-project/
├─ src/
│ ├─ index.js
├─ tsconfig.json
The following code:
import ts from 'typescript';
let tsConfigFile = ts.findConfigFile(
process.cwd(),
ts.sys.fileExists,
"tsconfig.json"
);
const { config } = ts.readConfigFile(tsConfigFile, ts.sys.readFile);
const program = ts.createProgram(['src/index.js'], config);
program.getSourceFiles().forEach((sf) => {
console.log(1, sf.fileName);
});
Where tsconfig.json looks like:
{
"compilerOptions": {
"strict": true,
"outDir": "./dist-types",
"target": "ESNext",
"allowSyntheticDefaultImports": true,
"moduleResolution": "NodeNext",
"module": "NodeNext",
"lib": ["ESNext", "DOM"],
"declaration": true,
"emitDeclarationOnly": true,
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"verbatimModuleSyntax": true
},
"include": [
"src/index.js"
],
"exclude": ["node_modules"],
}
Outputs:
1 /Users/au87xu/cem-typescript-issue/node_modules/typescript/lib/lib.d.ts
1 /Users/au87xu/cem-typescript-issue/node_modules/typescript/lib/lib.es5.d.ts
1 /Users/au87xu/cem-typescript-issue/node_modules/typescript/lib/lib.dom.d.ts
1 /Users/au87xu/cem-typescript-issue/node_modules/typescript/lib/lib.webworker.importscripts.d.ts
1 /Users/au87xu/cem-typescript-issue/node_modules/typescript/lib/lib.scripthost.d.ts
1 /Users/au87xu/cem-typescript-issue/node_modules/typescript/lib/lib.decorators.d.ts
1 /Users/au87xu/cem-typescript-issue/node_modules/typescript/lib/lib.decorators.legacy.d.ts
but src/index.js is missing from the source files. I feel like this did work in the past, or at least should work on regular js files as well.
⏯ Playground Link
n/a
💻 Code
// Your code here
🙁 Actual behavior
ts.createProgram does not include src/index.js
🙂 Expected behavior
ts.createProgram does include src/index.js
Additional information about the issue
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the issue's createProgram example and the referenced tsconfig-related APIs, including findConfigFile and readConfigFile. Document how these APIs should be used with JavaScript files in the wiki, including the observed source-file behavior; done when the relevant usage and expected behavior are clear to readers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100