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
{{ message }}
Repository navigation
TypeScript includes declaration merges from declaration file in typeRoots without import #20610
I am trying to create a local type declaration file for winston-papertrail that adds a new property to winston.transports.Papertrail. There is a @types/winston but no @types/winston-papertrail. Requiring "winston-papertrail" should augment winston.transports to also contain this additional Papertrail property. My assumption was that types inside of 'typeRoots' do not take effect until after the corresponding import statement has been made.
{
"compilerOptions": {
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"strict": true, /* Enable all strict type-checking options. */
"typeRoots": [ "node_modules/@types", "types" ] /* List of folders to include type definitions from. */
},
"include": [ "index.ts" ]
}
types/winston-papertrail/index.d.ts:
import * as winston from 'winston'
declare module "winston" {
interface Transports {
Papertrail: any
}
}
export { }
Expected behavior:
The expected behavior is that the Papertrail property is NOT showing up in the autocompletion suggestions for properties on the winston.transports value since I haven't imported "winston-papertrail" yet.
Actual behavior:
The Papertrail property is showing up in the autocompletion suggestions.
So does it then mean that the structure of the Types (@types) folder is irrelevant? By default every node_modules/@types/foobar/index.d.ts is included? I fooled myself into thinking that whether they are included or not would be controller by the import statements in your code, because the Types (@types) structure reflects the actual package names that you import.
Activity
sgronblo commentedon Dec 12, 2017
I see, then everything is as expected. Is this behavior documented somewhere, though? Personally I found it a bit unituitive.
sgronblo commentedon Dec 13, 2017
So does it then mean that the structure of the Types (@types) folder is irrelevant? By default every node_modules/@types/foobar/index.d.ts is included? I fooled myself into thinking that whether they are included or not would be controller by the import statements in your code, because the Types (@types) structure reflects the actual package names that you import.
sgronblo commentedon Dec 14, 2017
Gotcha, thanks