node-enumerable icon indicating copy to clipboard operation
node-enumerable copied to clipboard

Typescript semantic error: A type predicate's type must be assignable to its parameter's type

Open SeanSobey opened this issue 8 years ago • 2 comments

This comes from the index.d.ts, specifically these 3 functions:

function isNullOrEmpty<T>(seq: IEnumerable<T>): seq is (null | IEnumerable<T>);
function isUndefinedNullOrEmpty<T>(seq: IEnumerable<T>): seq is (undefined | null | IEnumerable<T>);
function isUndefinedOrEmpty<T>(seq: IEnumerable<T>): seq is (undefined | IEnumerable<T>);

I believe the correct semantics, also based on their names and what they should be able to accept as parameters is:

function isNullOrEmpty<T>(seq: null | IEnumerable<T>): seq is (null | IEnumerable<T>);
function isUndefinedNullOrEmpty<T>(seq: undefined | null | IEnumerable<T>): seq is (undefined | null | IEnumerable<T>);
function isUndefinedOrEmpty<T>(seq: undefined | IEnumerable<T>): seq is (undefined | IEnumerable<T>);

I am using typescript 2.7.2.

SeanSobey avatar Feb 19 '18 09:02 SeanSobey

@SeanSobey

Do you use compiler options like strict?

mkloubert avatar Feb 19 '18 10:02 mkloubert

Yes, here is the set of options I am using:

"compilerOptions": {
	"allowJs": true,
	"allowSyntheticDefaultImports": true,
	"checkJs": false,
	"emitDecoratorMetadata": true,
	"experimentalDecorators": true,
	"forceConsistentCasingInFileNames": true,
	"importHelpers": true,
	"module": "commonjs",
	"noFallthroughCasesInSwitch": true,
	"noImplicitAny": false,
	"noImplicitReturns": true,
	"noImplicitThis": true,
	"noUnusedLocals": true,
	"noUnusedParameters": false,
	"pretty": true,
	"skipLibCheck": false,
	"sourceMap": true,
	"strictNullChecks": true,
	"strict": true,
	"target": "es2017"
}

SeanSobey avatar Feb 19 '18 10:02 SeanSobey