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
type, non-ts module, type resolver, type generator
Suggestion
a type generation plugin system for non-ts modules.
Use Cases
useful to get type and autocomplete intellisense when importing non-ts modules like css, html, vue, etc.
currently there is only a generic type for a single type of file using .d.ts
Examples
While using typescript with some packing system like webpack, it's common import thing other than ts in a ts file, like js, css, html. For js file, typescript compiler can infer some type in js, or if you write types in jsdoc format. But other than ts and js, normally you will get cannot find definition for xxx, and you need to write a module declaration file like css.d.ts probably like this
and typescript-css-module-type-resolver in this format
interfacetypeDefinition{// a ts readable type definition tree}interfaceTSTypeResolverContext{options: any// possible optionsfilePath: string// file pathfileContent: string// file content in stringfileBuffer: Buffer// file content in bufferignore: function// ignore for this fileresolve: (filePath: string)=>typeDefinition// get definition for another filecallback: (type: typeDefinition)=>any// return the type generated by this plugin}constcssModuleTypeResolver=(context: TSTypeResolverContext)=>{const{
filePath,
fileContent,
fileBuffer,
ignore,
callback,}=contextif(filePath.match(/\.css$/)){// parse the file and generate the type// if (importInCss) {// resolveSomeOtherFiles// }constgeneratedType=typeGeneratedByThisPlugincallback(generatedType)}}exportdefaultcssModuleTypeResolver
to be use by ts compiler for any ts module import a css module file, and get type and auto complete intellisense like a normal ts file, and looks like this
and any other type of file could write a type plugin like this.
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript / JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. new expression-level syntax)
The text was updated successfully, but these errors were encountered:
noe132
changed the title
Proposal: module type resolver plugin
Proposal: non-ts module type resolver plugin
May 31, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Search Terms
type, non-ts module, type resolver, type generator
Suggestion
a type generation plugin system for non-ts modules.
Use Cases
useful to get type and autocomplete intellisense when importing non-ts modules like css, html, vue, etc.
currently there is only a generic type for a single type of file using
.d.ts
Examples
While using typescript with some packing system like webpack, it's common import thing other than ts in a ts file, like js, css, html. For js file, typescript compiler can infer some type in js, or if you write types in jsdoc format. But other than ts and js, normally you will get cannot find definition for xxx, and you need to write a module declaration file like
css.d.ts
probably like thisbut if we are importing a css module, you may need some thing like
which is simple and rude for css module type define.
So, if the type definition of a file can be generated by a plugin, for instance define a typePlugin in compilerOptions
and
typescript-css-module-type-resolver
in this formatwhich given a type like
to be use by ts compiler for any ts module import a css module file, and get type and auto complete intellisense like a normal ts file, and looks like this
and any other type of file could write a type plugin like this.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: