Skip to content
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

Correctly merge default compiler options #18

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,35 @@ When you have spread your tests over multiple files, you can store all those fil

Now you can put all your test files in the `my-test-dir` directory.

### Custom TypeScript config

By default, `tsd-check` applies the following cofiguration:
BendingBender marked this conversation as resolved.
Show resolved Hide resolved

```json5
{
"strict": true,
"jsx": "React",
"target": "ES2017",
// following options are set and are not overridable:
"moduleResolution": "Node",
"skipLibCheck": true
}
```

If you wish override these options, you have the possibility to provide a custom TypeScript config to `tsd-check` by specifying it in `package.json`.
BendingBender marked this conversation as resolved.
Show resolved Hide resolved

*Default options will still apply if you don't override them explicitly.* You can't override the `moduleResolution` and `skipLibCheck` options.

```json
{
"name": "my-module",
"tsd-check": {
"compilerOptions": {
"strict": false
}
}
}
```

## Assertions

Expand Down
18 changes: 7 additions & 11 deletions source/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ import {Config} from './interfaces';
* @param pkg - The package.json object.
* @returns The config object.
*/
export default (pkg: any): Config => {
const config = {
export default (pkg: {'tsd-check'?: Partial<Config>}): Config => {
const pkgConfig = pkg['tsd-check'] || {};

return {
directory: 'test-d',
...pkgConfig,
compilerOptions: {
strict: true,
jsx: JsxEmit.React,
target: ScriptTarget.ES2017
},
...pkg['tsd-check']
};

return {
...config,
compilerOptions: {
...config.compilerOptions,
target: ScriptTarget.ES2017,
...pkgConfig.compilerOptions,
...{
moduleResolution: ModuleResolutionKind.NodeJs,
skipLibCheck: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function (foo: number): number | null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.default = foo => {
return foo > 0 ? foo : null;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {expectType} from '../../..';
import aboveZero from '.';

expectType<number>(aboveZero(1));
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
BendingBender marked this conversation as resolved.
Show resolved Hide resolved
"name": "foo",
"tsd-check": {
"compilerOptions": {
}
}
}
31 changes: 19 additions & 12 deletions source/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,27 @@ test('fail if `typings` property is used instead of `types`', async t => {
});

test('fail if tests don\'t pass in strict mode', async t => {
const diagnostics = await m({
cwd: path.join(__dirname, 'fixtures/failure-strict-null-checks')
});

const {fileName, message, severity, line, column} = diagnostics[0];
t.true(/failure-strict-null-checks\/index.test-d.ts$/.test(fileName));
t.is(
message,
`Argument of type 'number | null' is not assignable to parameter of type 'number'.
function assert(diagnostics, expectedFilePathRe) {
const {fileName, message, severity, line, column} = diagnostics[0];
t.true(new RegExp(expectedFilePathRe).test(fileName));
t.is(
message,
`Argument of type 'number | null' is not assignable to parameter of type 'number'.
Type \'null\' is not assignable to type 'number'.`
);
t.is(severity, 'error');
t.is(line, 4);
t.is(column, 19);
}

assert(
BendingBender marked this conversation as resolved.
Show resolved Hide resolved
await m({cwd: path.join(__dirname, 'fixtures/failure-strict-null-checks')}),
'failure-strict-null-checks\\/index.test-d.ts$'
);
assert(
await m({cwd: path.join(__dirname, 'fixtures/failure-strict-null-checks-as-default-config-value')}),
'failure-strict-null-checks-as-default-config-value\\/index.test-d.ts$'
);
t.is(severity, 'error');
t.is(line, 4);
t.is(column, 19);
});

test('pass in loose mode when strict mode is disabled in settings', async t => {
Expand Down