-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bac42aa
commit 30f63ba
Showing
9 changed files
with
188 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as Effect from "effect/Effect" | ||
import * as Data from "effect/Data" | ||
|
||
class ErrorA extends Data.Error<{ | ||
a: 1 | ||
}>{} | ||
|
||
class ErrorB extends Data.Error<{ | ||
a: 2 | ||
}>{} | ||
|
||
class ErrorC extends Data.Error<{ | ||
a: 3 | ||
}>{} | ||
|
||
declare const effectWithErrors: Effect.Effect<number, ErrorA | ErrorB | ErrorC> | ||
|
||
function testFn(effect: Effect.Effect<number>){ | ||
return effect | ||
} | ||
|
||
// @ts-expect-error | ||
testFn(effectWithErrors) | ||
|
||
function testFnWithServiceAB(effect: Effect.Effect<number, ErrorA | ErrorB>){ | ||
return effect | ||
} | ||
|
||
// @ts-expect-error | ||
testFnWithServiceAB(effectWithErrors) |
35 changes: 35 additions & 0 deletions
35
examples/diagnostics/missingEffectError_plainAssignment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as Effect from "effect/Effect" | ||
import * as Data from "effect/Data" | ||
|
||
class ErrorA extends Data.Error<{ | ||
a: 1 | ||
}>{} | ||
|
||
class ErrorB extends Data.Error<{ | ||
a: 2 | ||
}>{} | ||
|
||
class ErrorC extends Data.Error<{ | ||
a: 3 | ||
}>{} | ||
|
||
declare const effectWithErrors: Effect.Effect<number, ErrorA | ErrorB | ErrorC> | ||
|
||
export const noError: Effect.Effect<number> = Effect.succeed(1) | ||
|
||
// @ts-expect-error | ||
export const missingAllErrors: Effect.Effect<number> = effectWithErrors | ||
|
||
// @ts-expect-error | ||
export const missingErrorC: Effect.Effect<number, ErrorA | ErrorB> = effectWithErrors | ||
|
||
export interface EffectSubtyping<A> extends Effect.Effect<A, ErrorA | ErrorB> {} | ||
|
||
// @ts-expect-error | ||
export const missingErrorCWithSubtyping: EffectSubtyping<number> = effectWithErrors | ||
|
||
export function missingErrorWithGenericType<A>(error: A){ | ||
// @ts-expect-error | ||
const missingErrorA: Effect.Effect<never> = Effect.fail(error) | ||
return missingErrorA | ||
} |
27 changes: 27 additions & 0 deletions
27
examples/diagnostics/missingEffectError_returnSignature.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as Effect from "effect/Effect" | ||
import * as Data from "effect/Data" | ||
|
||
class ErrorA extends Data.Error<{ | ||
a: 1 | ||
}>{} | ||
|
||
class ErrorB extends Data.Error<{ | ||
a: 2 | ||
}>{} | ||
|
||
class ErrorC extends Data.Error<{ | ||
a: 3 | ||
}>{} | ||
|
||
declare const effectWithErrors: Effect.Effect<number, ErrorA | ErrorB | ErrorC> | ||
|
||
export function testFn(): Effect.Effect<number> { | ||
// @ts-expect-error | ||
return effectWithErrors | ||
} | ||
|
||
// @ts-expect-error | ||
export const conciseBody: () => Effect.Effect<number> = () => effectWithErrors | ||
|
||
// @ts-expect-error | ||
export const conciseBodyMissingServiceC: () => Effect.Effect<number, ErrorA | ErrorB> = () => effectWithErrors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as Option from "effect/Option" | ||
import type ts from "typescript" | ||
import type { ApplicableDiagnosticDefinition } from "../definition.js" | ||
import { createDiagnostic } from "../definition.js" | ||
import * as TypeCheckerApi from "../utils/TypeCheckerApi.js" | ||
import * as TypeParser from "../utils/TypeParser.js" | ||
|
||
export const missingEffectError = createDiagnostic({ | ||
code: 2, | ||
apply: (ts, program) => (sourceFile) => { | ||
const typeChecker = program.getTypeChecker() | ||
const effectDiagnostics: Array<ApplicableDiagnosticDefinition> = [] | ||
|
||
const visit = (node: ts.Node) => { | ||
const entries = TypeParser.expectedAndRealType(ts, typeChecker)(node) | ||
for (const [node, expectedType, valueNode, realType] of entries) { | ||
Option.gen(function*() { | ||
const expectedEffect = yield* TypeParser.effectTypeArguments(ts, typeChecker)( | ||
expectedType, | ||
node | ||
) | ||
const realEffect = yield* TypeParser.effectTypeArguments(ts, typeChecker)( | ||
realType, | ||
valueNode | ||
) | ||
|
||
const missingErrorTypes = TypeCheckerApi.getMissingTypeEntriesInTargetType( | ||
ts, | ||
typeChecker | ||
)( | ||
realEffect.E, | ||
expectedEffect.E | ||
) | ||
if (missingErrorTypes.length > 0) { | ||
effectDiagnostics.push( | ||
{ | ||
node, | ||
category: ts.DiagnosticCategory.Error, | ||
messageText: `Missing '${ | ||
missingErrorTypes.map((_) => typeChecker.typeToString(_)).join(" | ") | ||
}' in the expected Effect errors.` | ||
} | ||
) | ||
} | ||
}) | ||
} | ||
ts.forEachChild(node, visit) | ||
} | ||
ts.forEachChild(sourceFile, visit) | ||
|
||
return effectDiagnostics | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters