mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 10:55:15 -06:00
Merge pull request #11791 from Microsoft/genericTypeParameterConstraint
Check type parameters of the type alias declaration
This commit is contained in:
commit
e38c004f90
@ -17434,6 +17434,7 @@ namespace ts {
|
||||
checkGrammarDecorators(node) || checkGrammarModifiers(node);
|
||||
|
||||
checkTypeNameIsReserved(node.name, Diagnostics.Type_alias_name_cannot_be_0);
|
||||
checkTypeParameters(node.typeParameters);
|
||||
checkSourceElement(node.type);
|
||||
}
|
||||
|
||||
|
||||
14
tests/baselines/reference/nounusedTypeParameterConstraint.js
Normal file
14
tests/baselines/reference/nounusedTypeParameterConstraint.js
Normal file
@ -0,0 +1,14 @@
|
||||
//// [tests/cases/compiler/nounusedTypeParameterConstraint.ts] ////
|
||||
|
||||
//// [bar.ts]
|
||||
|
||||
export interface IEventSourcedEntity { }
|
||||
|
||||
//// [test.ts]
|
||||
import { IEventSourcedEntity } from "./bar";
|
||||
export type DomainEntityConstructor<TEntity extends IEventSourcedEntity> = { new(): TEntity; };
|
||||
|
||||
//// [bar.js]
|
||||
"use strict";
|
||||
//// [test.js]
|
||||
"use strict";
|
||||
@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/bar.ts ===
|
||||
|
||||
export interface IEventSourcedEntity { }
|
||||
>IEventSourcedEntity : Symbol(IEventSourcedEntity, Decl(bar.ts, 0, 0))
|
||||
|
||||
=== tests/cases/compiler/test.ts ===
|
||||
import { IEventSourcedEntity } from "./bar";
|
||||
>IEventSourcedEntity : Symbol(IEventSourcedEntity, Decl(test.ts, 0, 8))
|
||||
|
||||
export type DomainEntityConstructor<TEntity extends IEventSourcedEntity> = { new(): TEntity; };
|
||||
>DomainEntityConstructor : Symbol(DomainEntityConstructor, Decl(test.ts, 0, 44))
|
||||
>TEntity : Symbol(TEntity, Decl(test.ts, 1, 36))
|
||||
>IEventSourcedEntity : Symbol(IEventSourcedEntity, Decl(test.ts, 0, 8))
|
||||
>TEntity : Symbol(TEntity, Decl(test.ts, 1, 36))
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/bar.ts ===
|
||||
|
||||
export interface IEventSourcedEntity { }
|
||||
>IEventSourcedEntity : IEventSourcedEntity
|
||||
|
||||
=== tests/cases/compiler/test.ts ===
|
||||
import { IEventSourcedEntity } from "./bar";
|
||||
>IEventSourcedEntity : any
|
||||
|
||||
export type DomainEntityConstructor<TEntity extends IEventSourcedEntity> = { new(): TEntity; };
|
||||
>DomainEntityConstructor : new () => TEntity
|
||||
>TEntity : TEntity
|
||||
>IEventSourcedEntity : IEventSourcedEntity
|
||||
>TEntity : TEntity
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
tests/cases/compiler/typeAliasDeclarationEmit.ts(4,37): error TS2314: Generic type 'callback' requires 1 type argument(s).
|
||||
|
||||
|
||||
==== tests/cases/compiler/typeAliasDeclarationEmit.ts (1 errors) ====
|
||||
|
||||
export type callback<T> = () => T;
|
||||
|
||||
export type CallbackArray<T extends callback> = () => T;
|
||||
~~~~~~~~
|
||||
!!! error TS2314: Generic type 'callback' requires 1 type argument(s).
|
||||
8
tests/cases/compiler/nounusedTypeParameterConstraint.ts
Normal file
8
tests/cases/compiler/nounusedTypeParameterConstraint.ts
Normal file
@ -0,0 +1,8 @@
|
||||
//@noUnusedLocals:true
|
||||
|
||||
//@filename: bar.ts
|
||||
export interface IEventSourcedEntity { }
|
||||
|
||||
//@filename: test.ts
|
||||
import { IEventSourcedEntity } from "./bar";
|
||||
export type DomainEntityConstructor<TEntity extends IEventSourcedEntity> = { new(): TEntity; };
|
||||
@ -128,7 +128,7 @@ function dir(dirPath: string, spec?: string, options?: any) {
|
||||
// fs.rmdirSync won't delete directories with files in it
|
||||
function deleteFolderRecursive(dirPath: string) {
|
||||
if (fs.existsSync(dirPath)) {
|
||||
fs.readdirSync(dirPath).forEach((file, index) => {
|
||||
fs.readdirSync(dirPath).forEach((file) => {
|
||||
const curPath = path.join(path, file);
|
||||
if (fs.statSync(curPath).isDirectory()) { // recurse
|
||||
deleteFolderRecursive(curPath);
|
||||
@ -141,7 +141,7 @@ function deleteFolderRecursive(dirPath: string) {
|
||||
}
|
||||
};
|
||||
|
||||
function writeFile(path: string, data: any, opts: { recursive: boolean }) {
|
||||
function writeFile(path: string, data: any) {
|
||||
ensureDirectoriesExist(getDirectoryPath(path));
|
||||
fs.writeFileSync(path, data);
|
||||
}
|
||||
@ -208,7 +208,7 @@ enum RequestType {
|
||||
Unknown
|
||||
}
|
||||
|
||||
function getRequestOperation(req: http.ServerRequest, filename: string) {
|
||||
function getRequestOperation(req: http.ServerRequest) {
|
||||
if (req.method === "GET" && req.url.indexOf("?") === -1) {
|
||||
if (req.url.indexOf(".") !== -1) return RequestType.GetFile;
|
||||
else return RequestType.GetDir;
|
||||
@ -258,7 +258,7 @@ function handleRequestOperation(req: http.ServerRequest, res: http.ServerRespons
|
||||
break;
|
||||
case RequestType.WriteFile:
|
||||
processPost(req, res, (data) => {
|
||||
writeFile(reqPath, data, { recursive: true });
|
||||
writeFile(reqPath, data);
|
||||
});
|
||||
send(ResponseCode.Success, res, undefined);
|
||||
break;
|
||||
@ -306,7 +306,7 @@ http.createServer((req: http.ServerRequest, res: http.ServerResponse) => {
|
||||
log(`${req.method} ${req.url}`);
|
||||
const uri = url.parse(req.url).pathname;
|
||||
const reqPath = path.join(process.cwd(), uri);
|
||||
const operation = getRequestOperation(req, reqPath);
|
||||
const operation = getRequestOperation(req);
|
||||
handleRequestOperation(req, res, operation, reqPath);
|
||||
}).listen(port);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user