-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Module or import
types
#22592
Module or import
types
#22592
Changes from 14 commits
9c69227
e9d01ce
31afd58
6ceaee0
fa9fe50
5d2715c
79c4729
9e77045
080ba6f
0be6ce4
73075dd
fefa9da
b07fe67
20950c5
8a8efc9
7521c63
257b848
a06607a
87b102e
7770788
d24ae2e
fbd6ce8
0c143a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,6 +284,7 @@ namespace ts { | |
IndexedAccessType, | ||
MappedType, | ||
LiteralType, | ||
ImportTypeNode, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @weswigham is in intentional that this is the only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. T.T no, I just unconsciously reused the interface name (which always uses |
||
// Binding patterns | ||
ObjectBindingPattern, | ||
ArrayBindingPattern, | ||
|
@@ -445,7 +446,7 @@ namespace ts { | |
FirstFutureReservedWord = ImplementsKeyword, | ||
LastFutureReservedWord = YieldKeyword, | ||
FirstTypeNode = TypePredicate, | ||
LastTypeNode = LiteralType, | ||
LastTypeNode = ImportTypeNode, | ||
FirstPunctuation = OpenBraceToken, | ||
LastPunctuation = CaretEqualsToken, | ||
FirstToken = Unknown, | ||
|
@@ -1066,6 +1067,16 @@ namespace ts { | |
| SyntaxKind.NeverKeyword; | ||
} | ||
|
||
export interface ImportTypeNode extends NodeWithTypeArguments { | ||
kind: SyntaxKind.ImportTypeNode; | ||
isTypeOf?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you curious why I didn't modify type queries to allow import type nodes somehow? (Perhaps because you dislike 1-token loohaheads or think this feels inelegant?) Well over here is a drop from awhile ago when I tried implementing this that way before, and it was really not pretty. Specifically, most places expect a type query's |
||
argument: TypeNode; | ||
qualifier?: EntityName; | ||
} | ||
|
||
/* @internal */ | ||
export type LiteralImportTypeNode = ImportTypeNode & { argument: LiteralTypeNode & { literal: StringLiteral } }; | ||
|
||
export interface ThisTypeNode extends TypeNode { | ||
kind: SyntaxKind.ThisType; | ||
} | ||
|
@@ -1080,12 +1091,15 @@ namespace ts { | |
kind: SyntaxKind.ConstructorType; | ||
} | ||
|
||
export interface NodeWithTypeArguments extends TypeNode { | ||
typeArguments?: NodeArray<TypeNode>; | ||
} | ||
|
||
export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; | ||
|
||
export interface TypeReferenceNode extends TypeNode { | ||
export interface TypeReferenceNode extends NodeWithTypeArguments { | ||
kind: SyntaxKind.TypeReference; | ||
typeName: EntityName; | ||
typeArguments?: NodeArray<TypeNode>; | ||
} | ||
|
||
export interface TypePredicateNode extends TypeNode { | ||
|
@@ -1695,11 +1709,10 @@ namespace ts { | |
expression: ImportExpression; | ||
} | ||
|
||
export interface ExpressionWithTypeArguments extends TypeNode { | ||
export interface ExpressionWithTypeArguments extends NodeWithTypeArguments { | ||
kind: SyntaxKind.ExpressionWithTypeArguments; | ||
parent?: HeritageClause; | ||
expression: LeftHandSideExpression; | ||
typeArguments?: NodeArray<TypeNode>; | ||
} | ||
|
||
export interface NewExpression extends PrimaryExpression, Declaration { | ||
|
@@ -2569,7 +2582,7 @@ namespace ts { | |
// Stores a mapping 'external module reference text' -> 'resolved file name' | undefined | ||
// It is used to resolve module names in the checker. | ||
// Content of this field should never be used directly - use getResolvedModuleFileName/setResolvedModuleFileName functions instead | ||
/* @internal */ resolvedModules: Map<ResolvedModuleFull | undefined>; | ||
/* @internal */ resolvedModules: Map<ResolvedModuleState>; | ||
/* @internal */ resolvedTypeReferenceDirectiveNames: Map<ResolvedTypeReferenceDirective>; | ||
/* @internal */ imports: ReadonlyArray<StringLiteralLike>; | ||
// Identifier only if `declare global` | ||
|
@@ -2583,6 +2596,9 @@ namespace ts { | |
/* @internal */ localJsxFactory?: EntityName; | ||
} | ||
|
||
/* @internal */ | ||
export type ResolvedModuleState = { tag: "success", data: ResolvedModuleFull } | { tag: "fail" }; | ||
|
||
export interface Bundle extends Node { | ||
kind: SyntaxKind.Bundle; | ||
sourceFiles: ReadonlyArray<SourceFile>; | ||
|
@@ -2705,6 +2721,9 @@ namespace ts { | |
/* @internal */ redirectTargetsSet: Map<true>; | ||
/** Is the file emitted file */ | ||
/* @internal */ isEmittedFile(file: string): boolean; | ||
|
||
/* Used by the type checker to resolve module names which are encountered late */ | ||
/* @internal */ resolveModuleName(moduleNames: string[], containingFile: string, reusedNames?: string[]): ResolvedModuleFull[]; | ||
} | ||
|
||
/* @internal */ | ||
|
@@ -2778,6 +2797,8 @@ namespace ts { | |
getSourceFiles(): ReadonlyArray<SourceFile>; | ||
getSourceFile(fileName: string): SourceFile; | ||
getResolvedTypeReferenceDirectives(): ReadonlyMap<ResolvedTypeReferenceDirective>; | ||
|
||
resolveModuleName(moduleNames: string[], containingFile: string, reusedNames?: string[]): ResolvedModuleFull[]; | ||
} | ||
|
||
export interface TypeChecker { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, not sure the type name here gives you much value.. we only allow string literals, not even strings.. so i would just say only string literals are valid import specifiers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll parse any type there to be permissive, though; this is more of a grammar error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. i am just saying whatever
{0}
is, the error message is just saying you cannot have it.. in other words, the type name is extraneousThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find including the type in the error message useful as frequently an error only exists because I believe that the type is correct at a given location; so seeing where reality differs from my expectation is useful.