-
Notifications
You must be signed in to change notification settings - Fork 8
What's New
- TypeScript 2.0 support
- #172 - Definition file supports strict null checks
-
#176 - Improved get and set accessor support. There is now a
kind
property which can be used to tell if a property has a get accessor, set accessor, or both. - #183 - TypeDefinition - Fix text and add node property.
- #189 - Remove user-defined type guards found on every definition.
- #182 - Fix enum definitions to show up in definitions array on a type when the type is an enum.
- Various improvements to imports and re-exports.
-
#169 -
renameDefinitionAs
bug fixes.
-
#171 -
ImportDefinition.namedImports
andReExportDefinition.namedImports
now has aname
andalias
property instead of animportName/exportName
property.
-
#132 -
InterfaceDefinition / ClassDefinition
-addExtends / addImplements
now accepts an interface or class. -
#168 -
setType
now accepts an interface or class. -
#169 -
GlobalDefinition
-renameDefinitionAs(def, newName)
can be used to rename a name everywhere it's used -
#113 - The order of a definition as a child of a module or file is stored in the
order
property. You can change the order of a definition in a module/file by usingsetDefintionOrder(definition: ModuleMemberDefinition, order: number)
, which might be useful when writing a file.
- All
typeExpression
-like names are now justtype
- Removed
TypeExpressionDefinition
- Plural add methods are now singular and return the created definition. Example:
namespaceDef.addFunctions({ ... }, { ...}, ...)
is nowconst functionDef = namespaceDef.addFunction({ ... });
- Lots of improvements to
type
arrayElementType
intersectionTypes
unionTypes
isArray()
getAllDefinitions()
- Supports generators—
isGenerator
- Allow specifying indentation for writing
-
const
enum support - Destructuring parameters support
-
setTypeExpression
,setDefaultExpression
,setReturnTypeExpression
manipulation methods -
GlobalDefinition
-addDefinitionAsImportToFile
method -
FileDefinition
-getModuleSpecifierToFile
method
- Support for user defined type guards
- Type expressions are no longer incorrectly cached
Previously, it would return an array:
// TSTypeInfo < 3.0
const files = TsTypeInfo.getInfoFromFiles(["V:/TestFile1.ts", "V:/TestFile2.ts"]);
const myClass = files[0].getClass("MyClass");
The problem with this is that it was kind of annoying to find a file by a file name and there wasn't a guarantee the array index would stay the same for a particular file. Now there are some helper methods for you:
// TSTypeInfo >= 3.0
const result = TsTypeInfo.getInfoFromFiles(["V:/TestFile1.ts", "V:/TestFile2.ts"]);
const myClass = result.getFile("TestFile1.ts").getClass("MyClass");
// or:
const myFileWithThreeClasses = result.getFile(f => f.classes.length === 3);
These are the helper methods currently available on this object:
-
.getFileOfDefinition(def)
- Gets the file a definition is located in -
.getFileAndNamespacesToDefinition(def)
- Returns the file a definition is located in, along with an array of namespaces that the definition is nested under in order (if any). -
.getFile(fileName | (def) => boolean)
- Gets a file by it's file name (does a simple endsWith comparison) or by a search function -
.addFiles(...)
- For code generation. Allows you to add new files under the result returned.
Previously, constructor parameters—ones with a scope—could be found on a class' properties array in addition to being stored as parameters in the constructor:
class MyClass {
constructor(public prop: string) {
}
}
// the above class would have the information:
myClass.constructor.parameters[0]; // { name: "prop", scope: ClassConstructorParameterScope.Public, ...etc...}
myClass.properties[0]; // { name: "prop", isConstructorParameter: true, ...etc... }
Now the isConstructorParameter
property is gone and the constructor parameters are only stored in the constructor.parameters
array. The reason this was done is to reduce duplication for code generation.
That being said, there is a new helper method that returns all the constructor parameters and properties. I would recommend using this when iterating a class' properties so you don't miss a constructor parameter:
// returns properties on the class and parameters in the constructor with a scope (ex. protected)
const propsAndConstructorParams = myClass.getPropertiesAndConstructorParameters();
Added all these functions:
createCallSignature
createCallSignatureParameter
createClass
createClassConstructor
createClassConstructorParameter
createClassMethod
createClassMethodParameter
createClassProperty
createClassStaticMethod
createClassStaticMethodParameter
createClassStaticProperty
createDecorator
createEnum
createEnumMember
-
createFile
-- already done createFunction
createFunctionParameter
createImport
createIndexSignature
createInterface
createInterfaceMethod
createInterfaceMethodParameter
createInterfaceProperty
createNamespace
createReExport
createTypeAlias
createVariable
It allows for code like the following:
import {createVariable} from "ts-type-info";
const myVar = createVariable({ name: "myVar", type: "string" });
console.log(myVar.write()); // outputs: let myVar: string;
-
TypeDefinition
getCallSignature
getDefinition
getProperty
getTypeArgument
-
TypeExpressionDefinition
getType
-
ImportDefinition
addNamedImports
setDefaultImport
getNamedImport
getStarImport
-
ReExportDefinition
addNamedExports
getNamedExport
getStarExport
-
async
keyword - Tuple types
- FileNotFound displays absolute path
- Write get and set accessors
- Write imports and re-exports
- Support
import "./name";
- Support star import with default import
- Added ability to bind writing methods in manipulation methods
- Fix thrown errors' message property (2.2.1)
- Fix error when calling createFile with no parameters (2.2.2)
- Multiple function signature support
- Interface index signatures
- Interface call signatures
- Improved writing
- #104 - Removed parent property to reduce complexity
- #115 - FileDefinition.defaultExport -> FileDefinition.defaultExportExpression
- #109 - Using code-block-writer 3.0 - The writer now adds the appropriate indentation when passing it a newline
- #108 - Throw error when someone specifies a file that doesn't exist
There are a lot more manipulation methods now. For example: addInterfaces
, addArguments
, and addClasses
to only name a few.
myFunction.addParameters({
name: "myFirstParameter",
type: "string"
}, {
name: "mySecondParameter",
type: "number[]"
isRestParameter: true
});
Most objects now have get[Def]
methods. For example:
const myClass = file.getClass("MyClass");
// or
const firstClassWithThreeMethods = file.getClass(c => c.methods.length === 3);