microsoft / microsoft/TypeScript
strictFunctionTypes prevents an assignment not related to functions
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript Version: 3.3.0-dev.20181122
Search Terms:
covariance, contravariance, keyof, interface, class, generic
Code
interface IBase {
foo: string;
}
interface IDerived extends IBase {
bar: string;
}
type StringPropertyNames<T> = { [P in keyof T]: T[P] extends string ? P : never }[keyof T]
type StringProperties<T> = Pick<T, StringPropertyNames<T>>
interface Foo<T> {
readonly Bar: StringProperties<T>;
}
let baseProperties: StringProperties<IBase>
let derivedProperties: StringProperties<IDerived>
let baseInterface: Foo<IBase>
let derivedInterface: Foo<IDerived>
baseProperties = derivedProperties // no error
baseInterface = derivedInterface
tsc test.ts --strictFunctionTypes
Expected behavior:
Compiles without errors.
Actual behavior:
test.ts:23:1 - error TS2322: Type 'Foo<IDerived>' is not assignable to type 'Foo<IBase>'.
Property 'bar' is missing in type 'IBase' but required in type 'IDerived'.
23 baseInterface = derivedInterface
~~~~~~~~~~~~~
test.ts:6:5
6 bar: string;
~~~
'bar' is declared here.
Related Issues:
#24190
The documentation says:
Under --strictFunctionTypes function type parameter positions are checked contravariantly instead of bivariantly.
I couldn't find any information saying it should affect anything else.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci l’esempio fornito in test.ts con tsc test.ts --strictFunctionTypes e confronta i due risultati dell’assegnazione. Il payload non indica alcun file di implementazione né alcun test di regressione, quindi segui il percorso del controllo dei tipi per l’assegnazione del tipo mappato generico segnalata. Il lavoro è completato quando il comportamento di assegnazione segnalato corrisponde al risultato atteso senza introdurre regressioni nel controllo rigoroso dei parametri delle funzioni.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 28/100